From c3683b3c0ba5ce60c94b03d90cc31b790a4f6762 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sun, 16 Nov 2014 16:01:12 +0000 Subject: [PATCH] Correct recryption for stamping, permissions for -combine-pages --- blankowneruser.pdf | Bin 0 -> 1179 bytes cpdf.ml | 46 ++++++++++++++++++++++++--------------------- cpdfcommand.ml | 4 +++- 3 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 blankowneruser.pdf diff --git a/blankowneruser.pdf b/blankowneruser.pdf new file mode 100644 index 0000000000000000000000000000000000000000..1bffc0390f7a94289182fd0bc4387b235d9dae61 GIT binary patch literal 1179 zcmZuxQAkr!7!J&W`{J`ia(Y;7k)GXcch0hfZjN+Q*PWI!M_hN$Y&P%FbI;OApe05I zf`v~8MbSe=Le-))=<}N2qDK)eD)QOgx(dSt$F%`s;&!5E zwPre&6nc~f1qFPb6b{k6!I6xkS=~%F2v#YZmTadqE#~-Zn(U9rlNd&@tDDd)YLclP+2VUe*(IXDmJy&NM5tILCe5=nF_Gx60$qc{sfmPR>i(K+ z{?_O$n(Ex0?+umHw{OmLRUNz(Z(E(-UXboaiR*<2fG z>FhaIx1K-SXIyP9V%?iUD(Bkb# zaLv#)rsE5+#47UOPUrku9}ib&PK<_|{~fM7^Pu|IihI3}KmL5EW^C(j)%Y9i!rjh$ zKNgSAwVgiddop`%;pgPZ)%fz)4{ZMR>_)}r$fr=uh2yB!2cv5ZC!L9h`o@curI$~) q-kBE<7>lmGND8+a8H%=PCbHx3Tku- - 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 _