Added plumbing for recrypting split PDFs

This commit is contained in:
John Whitington 2014-10-28 11:24:29 +00:00
parent 6e86e7778a
commit 15f57035fb
3 changed files with 59 additions and 13 deletions

31
cpdf.ml
View File

@ -1192,7 +1192,11 @@ let really_write_pdf ~preserve_objstm ~create_objstm ?(encryption = None) ?(cpdf
raise (Pdf.PDFError "linearizer failed")
end
let fast_write_split_pdfs enc splitlevel original_filename linearize ?(cpdflin = None) preserve_objstm create_objstm sq nobble spec main_pdf pagenums pdf_pages =
let fast_write_split_pdfs
recrypt was_encrypted was_decrypted_with_owner enc splitlevel
original_filename linearize ?(cpdflin = None) preserve_objstm
create_objstm sq nobble spec main_pdf pagenums pdf_pages
=
let marks = Pdfmarks.read_bookmarks main_pdf in
iter2
(fun number pagenums ->
@ -1205,10 +1209,16 @@ let fast_write_split_pdfs enc splitlevel original_filename linearize ?(cpdflin =
(indx pagenums)
pagenums
let split_pdf enc original_filename chunksize linearize ~cpdflin ~preserve_objstm ~create_objstm ~squeeze nobble spec pdf =
let split_pdf
recrypt was_encrypted was_decrypted_with_owner enc original_filename
chunksize linearize ~cpdflin ~preserve_objstm ~create_objstm ~squeeze
nobble spec pdf
=
let pdf_pages = Pdfpage.pages_of_pagetree pdf in
fast_write_split_pdfs enc 0 original_filename linearize preserve_objstm
create_objstm squeeze nobble spec pdf (splitinto chunksize (indx pdf_pages)) pdf_pages
fast_write_split_pdfs
recrypt was_encrypted was_decrypted_with_owner
enc 0 original_filename linearize preserve_objstm create_objstm
squeeze nobble spec pdf (splitinto chunksize (indx pdf_pages)) pdf_pages
(* Return list, in order, a *set* of page numbers of bookmarks at a given level *)
let bookmark_pages level pdf =
@ -1217,15 +1227,20 @@ let bookmark_pages level pdf =
(function l when l.Pdfmarks.level = level -> Some (Pdfpage.pagenumber_of_target pdf l.Pdfmarks.target) | _ -> None)
(Pdfmarks.read_bookmarks pdf))
let split_at_bookmarks original_filename linearize ~cpdflin ~preserve_objstm ~create_objstm ~squeeze nobble level spec pdf =
let split_at_bookmarks
recrypt was_encrypted was_decrypted_with_owner original_filename linearize
~cpdflin ~preserve_objstm ~create_objstm ~squeeze nobble level spec pdf
=
let pdf_pages = Pdfpage.pages_of_pagetree pdf in
let points = bookmark_pages level pdf in
let points =
lose (fun x -> x <= 0 || x > Pdfpage.endpage pdf) (map pred points)
in
let pts = splitat points (indx pdf_pages) in
fast_write_split_pdfs None level
original_filename linearize preserve_objstm create_objstm squeeze nobble spec pdf pts pdf_pages
let pts = splitat points (indx pdf_pages) in
fast_write_split_pdfs
recrypt was_encrypted was_decrypted_with_owner None level
original_filename linearize preserve_objstm create_objstm
squeeze nobble spec pdf pts pdf_pages
(* Called from cpdflib.ml - different from above *)
let split_on_bookmarks pdf level =

View File

@ -208,7 +208,21 @@ val stamp : position -> bool -> bool -> bool -> int list -> Pdf.t -> Pdf.t -> Pd
the fiven level, writing to files with names given by [spec] (see
cpdfmanual.pdf). [nobble] is undocumented and should be false. If [linearize]
is true, the files will be linearized. *)
val split_at_bookmarks : string -> bool -> cpdflin:string option -> preserve_objstm:bool -> create_objstm:bool -> squeeze:bool -> (Pdf.t -> Pdf.t) -> int -> string -> Pdf.t -> unit
val split_at_bookmarks :
bool ->
bool ->
bool ->
string ->
bool ->
cpdflin:string option ->
preserve_objstm:bool ->
create_objstm:bool ->
squeeze:bool ->
(Pdf.t -> Pdf.t) ->
int ->
string ->
Pdf.t ->
unit
(** Split a PDF on bookmarks of a given level or below. Level 0 is top level. *)
val split_on_bookmarks : Pdf.t -> int -> Pdf.t list
@ -220,8 +234,22 @@ each output is linearized. If [preserve_objstm] is true, object streams will
be used if the input file had them. If [create_objstm] is true, object
streams will be created in any event. [printf] and [nobble] are
undocumented and should be false. *)
val split_pdf : Pdfwrite.encryption option -> string -> int -> bool -> cpdflin:string option ->
preserve_objstm:bool -> create_objstm:bool -> squeeze:bool -> (Pdf.t -> Pdf.t) -> string -> Pdf.t -> unit
val split_pdf :
bool ->
bool ->
bool ->
Pdfwrite.encryption option ->
string ->
int ->
bool ->
cpdflin:string option ->
preserve_objstm:bool ->
create_objstm:bool ->
squeeze:bool ->
(Pdf.t -> Pdf.t) ->
string ->
Pdf.t ->
unit
(** {2 Listing fonts} *)

View File

@ -3066,6 +3066,7 @@ let go () =
Pdfwrite.permissions = banlist_of_args ()}
in
Cpdf.split_pdf
args.recrypt args.was_encrypted args.was_decrypted_with_owner
enc args.original_filename args.chunksize args.linearize args.cpdflin
args.preserve_objstm args.preserve_objstm (*yes--always create if preserving *)
args.squeeze nobble output_spec pdf
@ -3209,8 +3210,10 @@ let go () =
| [(InFile f, _, _, _, _)] -> f
| _ -> ""
in
Cpdf.split_at_bookmarks filename args.linearize args.cpdflin args.preserve_objstm
(* Yes *)args.preserve_objstm args.squeeze nobble level output_spec pdf
Cpdf.split_at_bookmarks
args.recrypt args.was_encrypted args.was_decrypted_with_owner
filename args.linearize args.cpdflin args.preserve_objstm
(* Yes *)args.preserve_objstm args.squeeze nobble level output_spec pdf
| Stdout -> error "Can't split to standard output"
| NoOutputSpecified -> error "Split: No output format specified"
end