Added plumbing for recrypting split PDFs
This commit is contained in:
parent
6e86e7778a
commit
15f57035fb
31
cpdf.ml
31
cpdf.ml
|
@ -1192,7 +1192,11 @@ let really_write_pdf ~preserve_objstm ~create_objstm ?(encryption = None) ?(cpdf
|
||||||
raise (Pdf.PDFError "linearizer failed")
|
raise (Pdf.PDFError "linearizer failed")
|
||||||
end
|
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
|
let marks = Pdfmarks.read_bookmarks main_pdf in
|
||||||
iter2
|
iter2
|
||||||
(fun number pagenums ->
|
(fun number pagenums ->
|
||||||
|
@ -1205,10 +1209,16 @@ let fast_write_split_pdfs enc splitlevel original_filename linearize ?(cpdflin =
|
||||||
(indx pagenums)
|
(indx pagenums)
|
||||||
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
|
let pdf_pages = Pdfpage.pages_of_pagetree pdf in
|
||||||
fast_write_split_pdfs enc 0 original_filename linearize preserve_objstm
|
fast_write_split_pdfs
|
||||||
create_objstm squeeze nobble spec pdf (splitinto chunksize (indx pdf_pages)) pdf_pages
|
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 *)
|
(* Return list, in order, a *set* of page numbers of bookmarks at a given level *)
|
||||||
let bookmark_pages level pdf =
|
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)
|
(function l when l.Pdfmarks.level = level -> Some (Pdfpage.pagenumber_of_target pdf l.Pdfmarks.target) | _ -> None)
|
||||||
(Pdfmarks.read_bookmarks pdf))
|
(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 pdf_pages = Pdfpage.pages_of_pagetree pdf in
|
||||||
let points = bookmark_pages level pdf in
|
let points = bookmark_pages level pdf in
|
||||||
let points =
|
let points =
|
||||||
lose (fun x -> x <= 0 || x > Pdfpage.endpage pdf) (map pred points)
|
lose (fun x -> x <= 0 || x > Pdfpage.endpage pdf) (map pred points)
|
||||||
in
|
in
|
||||||
let pts = splitat points (indx pdf_pages) in
|
let pts = splitat points (indx pdf_pages) in
|
||||||
fast_write_split_pdfs None level
|
fast_write_split_pdfs
|
||||||
original_filename linearize preserve_objstm create_objstm squeeze nobble spec pdf pts pdf_pages
|
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 *)
|
(* Called from cpdflib.ml - different from above *)
|
||||||
let split_on_bookmarks pdf level =
|
let split_on_bookmarks pdf level =
|
||||||
|
|
34
cpdf.mli
34
cpdf.mli
|
@ -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
|
the fiven level, writing to files with names given by [spec] (see
|
||||||
cpdfmanual.pdf). [nobble] is undocumented and should be false. If [linearize]
|
cpdfmanual.pdf). [nobble] is undocumented and should be false. If [linearize]
|
||||||
is true, the files will be linearized. *)
|
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. *)
|
(** 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
|
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
|
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
|
streams will be created in any event. [printf] and [nobble] are
|
||||||
undocumented and should be false. *)
|
undocumented and should be false. *)
|
||||||
val split_pdf : Pdfwrite.encryption option -> string -> int -> bool -> cpdflin:string option ->
|
val split_pdf :
|
||||||
preserve_objstm:bool -> create_objstm:bool -> squeeze:bool -> (Pdf.t -> Pdf.t) -> string -> Pdf.t -> unit
|
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} *)
|
(** {2 Listing fonts} *)
|
||||||
|
|
||||||
|
|
|
@ -3066,6 +3066,7 @@ let go () =
|
||||||
Pdfwrite.permissions = banlist_of_args ()}
|
Pdfwrite.permissions = banlist_of_args ()}
|
||||||
in
|
in
|
||||||
Cpdf.split_pdf
|
Cpdf.split_pdf
|
||||||
|
args.recrypt args.was_encrypted args.was_decrypted_with_owner
|
||||||
enc args.original_filename args.chunksize args.linearize args.cpdflin
|
enc args.original_filename args.chunksize args.linearize args.cpdflin
|
||||||
args.preserve_objstm args.preserve_objstm (*yes--always create if preserving *)
|
args.preserve_objstm args.preserve_objstm (*yes--always create if preserving *)
|
||||||
args.squeeze nobble output_spec pdf
|
args.squeeze nobble output_spec pdf
|
||||||
|
@ -3209,8 +3210,10 @@ let go () =
|
||||||
| [(InFile f, _, _, _, _)] -> f
|
| [(InFile f, _, _, _, _)] -> f
|
||||||
| _ -> ""
|
| _ -> ""
|
||||||
in
|
in
|
||||||
Cpdf.split_at_bookmarks filename args.linearize args.cpdflin args.preserve_objstm
|
Cpdf.split_at_bookmarks
|
||||||
(* Yes *)args.preserve_objstm args.squeeze nobble level output_spec pdf
|
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"
|
| Stdout -> error "Can't split to standard output"
|
||||||
| NoOutputSpecified -> error "Split: No output format specified"
|
| NoOutputSpecified -> error "Split: No output format specified"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue