From bc20b01061ee5c8d7e4b0911f4d6fe596bbcfdf5 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sun, 24 Jul 2016 14:53:24 +0100 Subject: [PATCH] Fixed outlines in -stamp-on, -stamp-under --- cpdf.ml | 15 ++++++++++++--- cpdfcommand.ml | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index 07c8cfb..770909f 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -2268,11 +2268,19 @@ let stamp relative_to_cropbox position topline midline fast scale_to_fit isover pageseqs under_pages in - let changed = Pdfpage.change_pages true merged new_pages in - let new_refnumbers = Pdf.page_reference_numbers changed in + let changed = Pdfpage.change_pages true merged (new_pages @ [last new_pages]) in + (* we use new_pages @ new_pages here to preserve the number of pages + * so that Pdfpage.change_pages can do its renumbering properly. + * Otherwise things like outlines are lost. TODO: Fix + * Pdfpage.change_pages properly. For now, we just use + * Pdfpage.pdf_of_pages afterward to chop it. *) + let cut = + Pdfpage.pdf_of_pages ~retain_numbering:true changed (ilist 1 (length new_pages)) + in + let new_refnumbers = Pdf.page_reference_numbers cut in let changetable = hashtable_of_dictionary (List.combine marks_refnumbers new_refnumbers) in let new_marks = map (change_bookmark changetable) marks in - Pdfmarks.add_bookmarks new_marks changed + Pdfmarks.add_bookmarks new_marks cut (* Combine pages from two PDFs. For now, assume equal length. *) @@ -2325,6 +2333,7 @@ let combine_pages (fast : bool) under over scaletofit swap equalize = * Otherwise things like outlines are lost. TODO: Fix * Pdfpage.change_pages properly. For now, we just use * Pdfpage.pdf_of_pages afterward to chop it. *) + (* See also combine_pages below *) let changed = Pdfpage.change_pages true merged (new_pages @ new_pages) in let cut = Pdfpage.pdf_of_pages ~retain_numbering:true changed (ilist 1 (length new_pages)) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index e73d74a..5280557 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1,10 +1,10 @@ (* Added -relative-to-cropbox for stamps *) (* cpdf command line tools *) let demo = false -let noncomp = true +let noncomp = false let major_version = 2 let minor_version = 2 -let version_date = "(build of 3rd April 2016)" +let version_date = "(build of 24th July 2016)" open Pdfutil open Pdfio