diff --git a/blankowneruser.pdf b/blankowneruser.pdf new file mode 100644 index 0000000..1bffc03 Binary files /dev/null and b/blankowneruser.pdf differ diff --git a/cpdf.ml b/cpdf.ml index 6fc06a3..1e538f2 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -2177,29 +2177,33 @@ let stamp position fast scale_to_fit isover range over pdf = ~rotations:[Pdfmerge.DNR; Pdfmerge.DNR] false false ["a"; "b"] [pdf; over_firstpage_pdf] [pageseqs; [1]] in - let renamed_pdf = - Pdfpage.change_pages true - merged (Pdfpage.renumber_pages merged (Pdfpage.pages_of_pagetree merged)) + let merged = + {merged with Pdf.saved_encryption = pdf.Pdf.saved_encryption} in - let renamed_pages = Pdfpage.pages_of_pagetree renamed_pdf in - let under_pages, over_page = - all_but_last renamed_pages, last renamed_pages - in - let new_pages = - map2 - (fun pageseq under_page -> - do_stamp fast position scale_to_fit isover renamed_pdf - (if mem pageseq range then over_page else - Pdfpage.blankpage Pdfpaper.a4) - under_page over) - pageseqs - under_pages + let merged = copy_id true pdf merged in + let renamed_pdf = + Pdfpage.change_pages true + merged (Pdfpage.renumber_pages merged (Pdfpage.pages_of_pagetree merged)) + in + let renamed_pages = Pdfpage.pages_of_pagetree renamed_pdf in + let under_pages, over_page = + all_but_last renamed_pages, last renamed_pages in - let changed = Pdfpage.change_pages true renamed_pdf new_pages in - let new_refnumbers = Pdf.page_reference_numbers changed 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 + let new_pages = + map2 + (fun pageseq under_page -> + do_stamp fast position scale_to_fit isover renamed_pdf + (if mem pageseq range then over_page else + Pdfpage.blankpage Pdfpaper.a4) + under_page over) + pageseqs + under_pages + in + let changed = Pdfpage.change_pages true renamed_pdf new_pages in + let new_refnumbers = Pdf.page_reference_numbers changed 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 (* Combine pages from two PDFs. For now, assume equal length. *) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index f7227d7..792a764 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -556,7 +556,9 @@ let banned banlist = function | ListBookmarks | ImageResolution _ | MissingFonts | PrintPageLabels | Clean | Compress | Decompress | RemoveUnusedResources | ChangeId | CopyId _ -> false (* Always allowed *) - | Decrypt | Encrypt -> true (* Never allowed *) + (* Combine pages is not allowed because we would not know where to get the + -recrypt from -- the first or second file? *) + | Decrypt | Encrypt | CombinePages _ -> true (* Never allowed *) | ExtractText | ExtractImages | ExtractFontFile -> mem Pdfcrypt.NoExtract banlist | AddBookmarks _ | PadBefore | PadAfter | PadEvery _ | PadMultiple _ | Merge | Split | SplitOnBookmarks _ | RotateContents _ | Rotate _