Correct recryption for stamping, permissions for -combine-pages

This commit is contained in:
John Whitington 2014-11-16 16:01:12 +00:00
parent b54a1e14c5
commit c3683b3c0b
3 changed files with 28 additions and 22 deletions

BIN
blankowneruser.pdf Normal file

Binary file not shown.

46
cpdf.ml
View File

@ -2177,29 +2177,33 @@ let stamp position fast scale_to_fit isover range over pdf =
~rotations:[Pdfmerge.DNR; Pdfmerge.DNR] ~rotations:[Pdfmerge.DNR; Pdfmerge.DNR]
false false ["a"; "b"] [pdf; over_firstpage_pdf] [pageseqs; [1]] false false ["a"; "b"] [pdf; over_firstpage_pdf] [pageseqs; [1]]
in in
let renamed_pdf = let merged =
Pdfpage.change_pages true {merged with Pdf.saved_encryption = pdf.Pdf.saved_encryption}
merged (Pdfpage.renumber_pages merged (Pdfpage.pages_of_pagetree merged))
in in
let renamed_pages = Pdfpage.pages_of_pagetree renamed_pdf in let merged = copy_id true pdf merged in
let under_pages, over_page = let renamed_pdf =
all_but_last renamed_pages, last renamed_pages Pdfpage.change_pages true
in merged (Pdfpage.renumber_pages merged (Pdfpage.pages_of_pagetree merged))
let new_pages = in
map2 let renamed_pages = Pdfpage.pages_of_pagetree renamed_pdf in
(fun pageseq under_page -> let under_pages, over_page =
do_stamp fast position scale_to_fit isover renamed_pdf all_but_last renamed_pages, last renamed_pages
(if mem pageseq range then over_page else
Pdfpage.blankpage Pdfpaper.a4)
under_page over)
pageseqs
under_pages
in in
let changed = Pdfpage.change_pages true renamed_pdf new_pages in let new_pages =
let new_refnumbers = Pdf.page_reference_numbers changed in map2
let changetable = hashtable_of_dictionary (List.combine marks_refnumbers new_refnumbers) in (fun pageseq under_page ->
let new_marks = map (change_bookmark changetable) marks in do_stamp fast position scale_to_fit isover renamed_pdf
Pdfmarks.add_bookmarks new_marks changed (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. *) (* Combine pages from two PDFs. For now, assume equal length. *)

View File

@ -556,7 +556,9 @@ let banned banlist = function
| ListBookmarks | ImageResolution _ | MissingFonts | ListBookmarks | ImageResolution _ | MissingFonts
| PrintPageLabels | Clean | Compress | Decompress | PrintPageLabels | Clean | Compress | Decompress
| RemoveUnusedResources | ChangeId | CopyId _ -> false (* Always allowed *) | 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 | ExtractText | ExtractImages | ExtractFontFile -> mem Pdfcrypt.NoExtract banlist
| AddBookmarks _ | PadBefore | PadAfter | PadEvery _ | PadMultiple _ | AddBookmarks _ | PadBefore | PadAfter | PadEvery _ | PadMultiple _
| Merge | Split | SplitOnBookmarks _ | RotateContents _ | Rotate _ | Merge | Split | SplitOnBookmarks _ | RotateContents _ | Rotate _