Added -cpdflin option

This commit is contained in:
John Whitington 2014-10-02 19:57:06 +01:00
parent 2062d0fb27
commit df0c6c4c45
3 changed files with 22 additions and 13 deletions

10
cpdf.ml
View File

@ -1451,7 +1451,7 @@ let name_of_spec printf marks (pdf : Pdf.t) splitlevel spec n filename startpage
let stem 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' =
if linearize
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';
if linearize then
let cpdflin =
match find_cpdflin None with
match find_cpdflin cpdflin with
Some x -> x
| None -> raise (Pdf.PDFError "Could not find cpdflin")
in
@ -1483,7 +1483,7 @@ let really_write_pdf ~preserve_objstm ~create_objstm ?(encryption = None) linear
raise (Pdf.PDFError "linearizer failed")
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
iter2
(fun number pagenums ->
@ -1496,7 +1496,7 @@ let fast_write_split_pdfs enc printf splitlevel original_filename linearize pres
(indx 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
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
@ -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)
(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 points = bookmark_pages level pdf in
let points =

View File

@ -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
cpdfmanual.pdf). [nobble] is undocumented and should be false. If [linearize]
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. *)
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
streams will be created in any event. [printf] and [nobble] are
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
(** {2 Listing fonts} *)

View File

@ -258,7 +258,8 @@ type args =
mutable labelprefix : string option;
mutable labelstartval : int;
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
overwrite any input file when -dont-overwrite-existing-files is used. *)
@ -342,7 +343,8 @@ let args =
labelprefix = None;
labelstartval = 1;
squeeze = false;
original_filename = ""}
original_filename = "";
cpdflin = None}
let reset_arguments () =
args.op <- None;
@ -419,7 +421,8 @@ let reset_arguments () =
args.squeeze <- false
(* 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
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 l = ref [] in
@ -1229,6 +1232,9 @@ let setlabelprefix s =
let setlabelstartval i =
args.labelstartval <- i
let setcpdflin s =
args.cpdflin <- Some s
(* Parse a control file, make an argv, and then make Arg parse it. *)
let rec make_control_argv_and_parse filename =
control_args := !control_args @ parse_control_file filename
@ -1276,6 +1282,9 @@ and specs =
("-l",
Arg.Unit setlinearize,
" Linearize output files where possible");
("-cpdflin",
Arg.String setcpdflin,
" Set location of 'cpdflin'");
("-raw",
Arg.Unit (setencoding Cpdf.Raw),
" Do not process text");
@ -1782,7 +1791,7 @@ let really_write_pdf ?(encryption = None) mk_id pdf outname =
false encryption mk_id pdf outname';
if args.linearize then
let cpdflin =
match Cpdf.find_cpdflin None with
match Cpdf.find_cpdflin args.cpdflin with
Some x -> x
| None -> raise (Pdf.PDFError "Could not find cpdflin")
in
@ -3104,7 +3113,7 @@ let go () =
Pdfwrite.permissions = banlist_of_args ()}
in
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.squeeze nobble output_spec pdf
| _, Stdout -> error "Can't split to standard output"
@ -3248,7 +3257,7 @@ let go () =
| [(InFile f, _, _, _, _)] -> f
| _ -> ""
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
| Stdout -> error "Can't split to standard output"
| NoOutputSpecified -> error "Split: No output format specified"