Squeeze logging
This commit is contained in:
parent
0f369f9584
commit
5025ff0d5b
19
cpdf.ml
19
cpdf.ml
|
@ -241,17 +241,26 @@ let squeeze_all_content_streams pdf =
|
||||||
|
|
||||||
(* We run squeeze enough times to reach a fixed point in the cardinality of the
|
(* We run squeeze enough times to reach a fixed point in the cardinality of the
|
||||||
* object map *)
|
* object map *)
|
||||||
let squeeze pdf =
|
let squeeze ?logto pdf =
|
||||||
|
let log x =
|
||||||
|
match logto with
|
||||||
|
None -> print_string x; flush stdout
|
||||||
|
| Some s ->
|
||||||
|
let fh = open_out_gen [Open_wronly; Open_creat] 0o666 s in
|
||||||
|
seek_out fh (out_channel_length fh);
|
||||||
|
output_string fh x;
|
||||||
|
close_out fh
|
||||||
|
in
|
||||||
try
|
try
|
||||||
let n = ref (Pdf.objcard pdf) in
|
let n = ref (Pdf.objcard pdf) in
|
||||||
Printf.printf "Beginning squeeze: %i objects\n%!" (Pdf.objcard pdf);
|
log (Printf.sprintf "Beginning squeeze: %i objects\n" (Pdf.objcard pdf));
|
||||||
while !n > (ignore (really_squeeze pdf); Pdf.objcard pdf) do
|
while !n > (ignore (really_squeeze pdf); Pdf.objcard pdf) do
|
||||||
n := Pdf.objcard pdf;
|
n := Pdf.objcard pdf;
|
||||||
Printf.printf "Squeezing... Down to %i objects\n%!" (Pdf.objcard pdf);
|
log (Printf.sprintf "Squeezing... Down to %i objects\n" (Pdf.objcard pdf));
|
||||||
done;
|
done;
|
||||||
Printf.printf "Squeezing page data and xobjects\n%!";
|
log (Printf.sprintf "Squeezing page data and xobjects\n");
|
||||||
squeeze_all_content_streams pdf;
|
squeeze_all_content_streams pdf;
|
||||||
Printf.printf "Recompressing document\n%!";
|
log (Printf.sprintf "Recompressing document\n");
|
||||||
Pdfcodec.flate_level := 9;
|
Pdfcodec.flate_level := 9;
|
||||||
ignore (recompress_pdf pdf)
|
ignore (recompress_pdf pdf)
|
||||||
with
|
with
|
||||||
|
|
2
cpdf.mli
2
cpdf.mli
|
@ -459,7 +459,7 @@ val blackfills : int list -> Pdf.t -> Pdf.t
|
||||||
val draft : bool -> int list -> Pdf.t -> Pdf.t
|
val draft : bool -> int list -> Pdf.t -> Pdf.t
|
||||||
|
|
||||||
(** Squeeze a PDF *)
|
(** Squeeze a PDF *)
|
||||||
val squeeze : Pdf.t -> unit
|
val squeeze : ?logto:string -> Pdf.t -> unit
|
||||||
|
|
||||||
(**/**)
|
(**/**)
|
||||||
|
|
||||||
|
|
|
@ -1333,6 +1333,11 @@ let setrecrypt () =
|
||||||
let setremovedictentry s =
|
let setremovedictentry s =
|
||||||
args.op <- Some (RemoveDictEntry s)
|
args.op <- Some (RemoveDictEntry s)
|
||||||
|
|
||||||
|
let logto = ref None
|
||||||
|
|
||||||
|
let setsqueezelogto s =
|
||||||
|
logto := 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
|
||||||
|
@ -1850,6 +1855,7 @@ and specs =
|
||||||
("-debug-crypt", Arg.Unit setdebugcrypt, "");
|
("-debug-crypt", Arg.Unit setdebugcrypt, "");
|
||||||
("-fix-prince", Arg.Unit (setop RemoveUnusedResources), "");
|
("-fix-prince", Arg.Unit (setop RemoveUnusedResources), "");
|
||||||
("-squeeze", Arg.Unit setsqueeze, "");
|
("-squeeze", Arg.Unit setsqueeze, "");
|
||||||
|
("-squeeze-log-to", Arg.String setsqueezelogto, "");
|
||||||
("-extract-text", Arg.Unit (setop ExtractText), "")]
|
("-extract-text", Arg.Unit (setop ExtractText), "")]
|
||||||
|
|
||||||
and usage_msg =
|
and usage_msg =
|
||||||
|
@ -2031,7 +2037,7 @@ let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf =
|
||||||
if not is_decompress then
|
if not is_decompress then
|
||||||
begin
|
begin
|
||||||
ignore (Cpdf.recompress_pdf pdf);
|
ignore (Cpdf.recompress_pdf pdf);
|
||||||
if args.squeeze then Cpdf.squeeze pdf;
|
if args.squeeze then Cpdf.squeeze ?logto:!logto pdf;
|
||||||
end;
|
end;
|
||||||
Pdf.remove_unreferenced pdf;
|
Pdf.remove_unreferenced pdf;
|
||||||
really_write_pdf ~is_decompress mk_id pdf outname
|
really_write_pdf ~is_decompress mk_id pdf outname
|
||||||
|
@ -2046,7 +2052,7 @@ let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf =
|
||||||
if not is_decompress then
|
if not is_decompress then
|
||||||
begin
|
begin
|
||||||
ignore (Cpdf.recompress_pdf pdf);
|
ignore (Cpdf.recompress_pdf pdf);
|
||||||
if args.squeeze then Cpdf.squeeze pdf;
|
if args.squeeze then Cpdf.squeeze ?logto:!logto pdf;
|
||||||
Pdf.remove_unreferenced pdf
|
Pdf.remove_unreferenced pdf
|
||||||
end;
|
end;
|
||||||
really_write_pdf ~encryption ~is_decompress mk_id pdf temp;
|
really_write_pdf ~encryption ~is_decompress mk_id pdf temp;
|
||||||
|
@ -2136,7 +2142,7 @@ let fast_write_split_pdfs
|
||||||
(stem original_filename) startpage endpage
|
(stem original_filename) startpage endpage
|
||||||
in
|
in
|
||||||
Pdf.remove_unreferenced pdf;
|
Pdf.remove_unreferenced pdf;
|
||||||
if sq then Cpdf.squeeze pdf;
|
if sq then Cpdf.squeeze ?logto:!logto pdf;
|
||||||
really_write_pdf ~encryption:enc (not (enc = None)) pdf name)
|
really_write_pdf ~encryption:enc (not (enc = None)) pdf name)
|
||||||
(indx pagenums)
|
(indx pagenums)
|
||||||
pagenums
|
pagenums
|
||||||
|
|
Loading…
Reference in New Issue