Added -cpdflin option
This commit is contained in:
parent
2062d0fb27
commit
df0c6c4c45
10
cpdf.ml
10
cpdf.ml
|
@ -1451,7 +1451,7 @@ let name_of_spec printf marks (pdf : Pdf.t) splitlevel spec n filename startpage
|
||||||
let stem s =
|
let stem s =
|
||||||
implode (rev (tail_no_fail (dropwhile (neq '.') (rev (explode (Filename.basename s))))))
|
implode (rev (tail_no_fail (dropwhile (neq '.') (rev (explode (Filename.basename s))))))
|
||||||
|
|
||||||
let really_write_pdf ~preserve_objstm ~create_objstm ?(encryption = None) linearize mk_id pdf outname =
|
let really_write_pdf ~preserve_objstm ~create_objstm ?(encryption = None) ?(cpdflin = None) linearize mk_id pdf outname =
|
||||||
let outname' =
|
let outname' =
|
||||||
if linearize
|
if linearize
|
||||||
then Filename.temp_file "cpdflin" ".pdf"
|
then Filename.temp_file "cpdflin" ".pdf"
|
||||||
|
@ -1463,7 +1463,7 @@ let really_write_pdf ~preserve_objstm ~create_objstm ?(encryption = None) linear
|
||||||
false encryption mk_id pdf outname';
|
false encryption mk_id pdf outname';
|
||||||
if linearize then
|
if linearize then
|
||||||
let cpdflin =
|
let cpdflin =
|
||||||
match find_cpdflin None with
|
match find_cpdflin cpdflin with
|
||||||
Some x -> x
|
Some x -> x
|
||||||
| None -> raise (Pdf.PDFError "Could not find cpdflin")
|
| None -> raise (Pdf.PDFError "Could not find cpdflin")
|
||||||
in
|
in
|
||||||
|
@ -1483,7 +1483,7 @@ let really_write_pdf ~preserve_objstm ~create_objstm ?(encryption = None) linear
|
||||||
raise (Pdf.PDFError "linearizer failed")
|
raise (Pdf.PDFError "linearizer failed")
|
||||||
end
|
end
|
||||||
|
|
||||||
let fast_write_split_pdfs enc printf splitlevel original_filename linearize preserve_objstm create_objstm sq nobble spec main_pdf pagenums pdf_pages =
|
let fast_write_split_pdfs enc printf 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 ->
|
||||||
|
@ -1496,7 +1496,7 @@ let fast_write_split_pdfs enc printf splitlevel original_filename linearize pres
|
||||||
(indx pagenums)
|
(indx pagenums)
|
||||||
pagenums
|
pagenums
|
||||||
|
|
||||||
let split_pdf enc printf original_filename chunksize linearize ~preserve_objstm ~create_objstm ~squeeze nobble spec pdf =
|
let split_pdf enc printf 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 printf 0 original_filename linearize preserve_objstm
|
fast_write_split_pdfs enc printf 0 original_filename linearize preserve_objstm
|
||||||
create_objstm squeeze nobble spec pdf (splitinto chunksize (indx pdf_pages)) pdf_pages
|
create_objstm squeeze nobble spec pdf (splitinto chunksize (indx pdf_pages)) pdf_pages
|
||||||
|
@ -1508,7 +1508,7 @@ 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 ~preserve_objstm ~create_objstm ~squeeze nobble level spec pdf =
|
let split_at_bookmarks 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 =
|
||||||
|
|
4
cpdf.mli
4
cpdf.mli
|
@ -189,7 +189,7 @@ val stamp : bool -> bool -> bool -> int list -> Pdf.t -> Pdf.t -> Pdf.t
|
||||||
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 -> preserve_objstm:bool -> create_objstm:bool -> squeeze:bool -> (Pdf.t -> Pdf.t) -> int -> string -> Pdf.t -> unit
|
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
|
||||||
|
|
||||||
(** 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
|
||||||
|
@ -201,7 +201,7 @@ 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 -> bool -> string -> int -> bool ->
|
val split_pdf : Pdfwrite.encryption option -> bool -> string -> int -> bool -> cpdflin:string option ->
|
||||||
preserve_objstm:bool -> create_objstm:bool -> squeeze:bool -> (Pdf.t -> Pdf.t) -> string -> Pdf.t -> unit
|
preserve_objstm:bool -> create_objstm:bool -> squeeze:bool -> (Pdf.t -> Pdf.t) -> string -> Pdf.t -> unit
|
||||||
|
|
||||||
(** {2 Listing fonts} *)
|
(** {2 Listing fonts} *)
|
||||||
|
|
|
@ -258,7 +258,8 @@ type args =
|
||||||
mutable labelprefix : string option;
|
mutable labelprefix : string option;
|
||||||
mutable labelstartval : int;
|
mutable labelstartval : int;
|
||||||
mutable squeeze : bool;
|
mutable squeeze : bool;
|
||||||
mutable original_filename : string}
|
mutable original_filename : string;
|
||||||
|
mutable cpdflin : string option}
|
||||||
|
|
||||||
(* List of all filenames in any AND stage - this is used to check that we don't
|
(* List of all filenames in any AND stage - this is used to check that we don't
|
||||||
overwrite any input file when -dont-overwrite-existing-files is used. *)
|
overwrite any input file when -dont-overwrite-existing-files is used. *)
|
||||||
|
@ -342,7 +343,8 @@ let args =
|
||||||
labelprefix = None;
|
labelprefix = None;
|
||||||
labelstartval = 1;
|
labelstartval = 1;
|
||||||
squeeze = false;
|
squeeze = false;
|
||||||
original_filename = ""}
|
original_filename = "";
|
||||||
|
cpdflin = None}
|
||||||
|
|
||||||
let reset_arguments () =
|
let reset_arguments () =
|
||||||
args.op <- None;
|
args.op <- None;
|
||||||
|
@ -419,7 +421,8 @@ let reset_arguments () =
|
||||||
args.squeeze <- false
|
args.squeeze <- false
|
||||||
(* We don't reset args.do_ask and args.verbose, because they operate on all
|
(* We don't reset args.do_ask and args.verbose, because they operate on all
|
||||||
parts of the AND-ed command line sent from cpdftk. Also do not reset
|
parts of the AND-ed command line sent from cpdftk. Also do not reset
|
||||||
original_filename, since we want it to work across AND sections. *)
|
original_filename, since we want it to work across AND sections. Also do not
|
||||||
|
reset cpdflin. *)
|
||||||
|
|
||||||
let banlist_of_args () =
|
let banlist_of_args () =
|
||||||
let l = ref [] in
|
let l = ref [] in
|
||||||
|
@ -1229,6 +1232,9 @@ let setlabelprefix s =
|
||||||
let setlabelstartval i =
|
let setlabelstartval i =
|
||||||
args.labelstartval <- i
|
args.labelstartval <- i
|
||||||
|
|
||||||
|
let setcpdflin s =
|
||||||
|
args.cpdflin <- Some s
|
||||||
|
|
||||||
(* Parse a control file, make an argv, and then make Arg parse it. *)
|
(* Parse a control file, make an argv, and then make Arg parse it. *)
|
||||||
let rec make_control_argv_and_parse filename =
|
let rec make_control_argv_and_parse filename =
|
||||||
control_args := !control_args @ parse_control_file filename
|
control_args := !control_args @ parse_control_file filename
|
||||||
|
@ -1276,6 +1282,9 @@ and specs =
|
||||||
("-l",
|
("-l",
|
||||||
Arg.Unit setlinearize,
|
Arg.Unit setlinearize,
|
||||||
" Linearize output files where possible");
|
" Linearize output files where possible");
|
||||||
|
("-cpdflin",
|
||||||
|
Arg.String setcpdflin,
|
||||||
|
" Set location of 'cpdflin'");
|
||||||
("-raw",
|
("-raw",
|
||||||
Arg.Unit (setencoding Cpdf.Raw),
|
Arg.Unit (setencoding Cpdf.Raw),
|
||||||
" Do not process text");
|
" Do not process text");
|
||||||
|
@ -1782,7 +1791,7 @@ let really_write_pdf ?(encryption = None) mk_id pdf outname =
|
||||||
false encryption mk_id pdf outname';
|
false encryption mk_id pdf outname';
|
||||||
if args.linearize then
|
if args.linearize then
|
||||||
let cpdflin =
|
let cpdflin =
|
||||||
match Cpdf.find_cpdflin None with
|
match Cpdf.find_cpdflin args.cpdflin with
|
||||||
Some x -> x
|
Some x -> x
|
||||||
| None -> raise (Pdf.PDFError "Could not find cpdflin")
|
| None -> raise (Pdf.PDFError "Could not find cpdflin")
|
||||||
in
|
in
|
||||||
|
@ -3104,7 +3113,7 @@ let go () =
|
||||||
Pdfwrite.permissions = banlist_of_args ()}
|
Pdfwrite.permissions = banlist_of_args ()}
|
||||||
in
|
in
|
||||||
Cpdf.split_pdf
|
Cpdf.split_pdf
|
||||||
enc args.printf_format args.original_filename args.chunksize args.linearize
|
enc args.printf_format 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
|
||||||
| _, Stdout -> error "Can't split to standard output"
|
| _, Stdout -> error "Can't split to standard output"
|
||||||
|
@ -3248,7 +3257,7 @@ let go () =
|
||||||
| [(InFile f, _, _, _, _)] -> f
|
| [(InFile f, _, _, _, _)] -> f
|
||||||
| _ -> ""
|
| _ -> ""
|
||||||
in
|
in
|
||||||
Cpdf.split_at_bookmarks filename args.linearize args.preserve_objstm
|
Cpdf.split_at_bookmarks filename args.linearize args.cpdflin args.preserve_objstm
|
||||||
(* Yes *)args.preserve_objstm args.squeeze nobble level output_spec pdf
|
(* 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"
|
||||||
|
|
Loading…
Reference in New Issue