Skip to content

Commit

Permalink
fix #71
Browse files Browse the repository at this point in the history
  • Loading branch information
Boaz Segev authored and Boaz Segev committed Jul 10, 2016
1 parent ad375c5 commit 0129eac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

***

Change log v.0.2.25

**Fix**: Fixed issue #71, merging PDF outline that exist but have 0 entries fails and raises an exception. Credit to @Kagetsuki for exposing the issue.

***

Change log v.0.2.24

**Fix**: Fixed an issue with PDF Catalog and PDF Page property inheritance that could cause corrupted PDF output (invalid PDF data). Credit to @Kagetsuki for openning an issue that let to this discovery.
Expand Down
7 changes: 5 additions & 2 deletions lib/combine_pdf/pdf_protected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,15 @@ def self.hash_merge_new_no_page(_key, old_data, new_data)
# :Dest - node link destination (if the node is linking to something)
def merge_outlines(old_data, new_data, position)
old_data = actual_object(old_data)
new_data = actual_object(new_data).dup
if old_data.empty?
new_data = actual_object(new_data)
if old_data.nil? || old_data.empty? || old_data[:First].nil?
# old_data is a reference to the actual object,
# so if we update old_data, we're done, no need to take any further action
old_data.update new_data
elsif new_data.nil? || new_data.empty? || new_data[:First].nil?
return old_data
else
new_data = new_data.dup # avoid old data corruption
# number of outline nodes, after the merge
old_data[:Count] += new_data[:Count]
# walk the Hash here ...
Expand Down
2 changes: 1 addition & 1 deletion lib/combine_pdf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CombinePDF
VERSION = "0.2.24"
VERSION = "0.2.25"
end
6 changes: 5 additions & 1 deletion test/automated
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pdf = CombinePDF.load "./Ruby/test pdfs/names_go_haywire_0.pdf"
pdf << CombinePDF.load("./Ruby/test pdfs/names_go_haywire_1.pdf")
pdf.save '04_check_view_and_names_reference.pdf'

str = IO.binread './Ruby/test pdfs/outlines/self_merge_err.pdf'
pdf = CombinePDF.load('./Ruby/test pdfs/outlines/self_merge_err.pdf')
pdf << CombinePDF.load('./Ruby/test pdfs/outlines/self_merge_err.pdf')
pdf.save "05_scribus_test.pdf"
# pdf = CombinePDF.load "./Ruby/test pdfs/named_dest.pdf";nil
# pdf.save '05_check_named_dest_links.pdf' # this will take a while
# pdf = CombinePDF.load "./Ruby/test pdfs/named_dest.pdf";nil
Expand All @@ -39,7 +43,7 @@ pdf << CombinePDF.load("./Ruby/test pdfs/outline_small.pdf")
pdf.save '06_check_links_to_second_copy.pdf'


lists = %w{./Ruby/test\ pdfs/outlines/big_toc.pdf ./Ruby/test\ pdfs/outlines/bigger_toc.pdf ./Ruby/test\ pdfs/outlines/named_dest_no_toc.pdf ./Ruby/test\ pdfs/outlines/named_dest_no_toc2.pdf ./Ruby/test\ pdfs/outlines/named_dest.pdf ./Ruby/test\ pdfs/outlines/named_dest2.pdf};
lists = %w{./Ruby/test\ pdfs/outlines/self_merge_err.pdf ./Ruby/test\ pdfs/outlines/big_toc.pdf ./Ruby/test\ pdfs/outlines/bigger_toc.pdf ./Ruby/test\ pdfs/outlines/named_dest_no_toc.pdf ./Ruby/test\ pdfs/outlines/named_dest_no_toc2.pdf ./Ruby/test\ pdfs/outlines/named_dest.pdf ./Ruby/test\ pdfs/outlines/named_dest2.pdf};

i = 0
lists.each{|n| CombinePDF.load(n).save("07_#{(i+=1).to_s}_#{n.split('/')[-1]}"); (CombinePDF.load(n) << CombinePDF.load(n)).save("07_#{(i).to_s}x2_#{n.split('/')[-1]}") }
Expand Down

0 comments on commit 0129eac

Please sign in to comment.