Squeeze logging
This commit is contained in:
parent
0f369f9584
commit
5025ff0d5b
49
cpdf.ml
49
cpdf.ml
|
@ -241,26 +241,35 @@ 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 =
|
||||||
try
|
let log x =
|
||||||
let n = ref (Pdf.objcard pdf) in
|
match logto with
|
||||||
Printf.printf "Beginning squeeze: %i objects\n%!" (Pdf.objcard pdf);
|
None -> print_string x; flush stdout
|
||||||
while !n > (ignore (really_squeeze pdf); Pdf.objcard pdf) do
|
| Some s ->
|
||||||
n := Pdf.objcard pdf;
|
let fh = open_out_gen [Open_wronly; Open_creat] 0o666 s in
|
||||||
Printf.printf "Squeezing... Down to %i objects\n%!" (Pdf.objcard pdf);
|
seek_out fh (out_channel_length fh);
|
||||||
done;
|
output_string fh x;
|
||||||
Printf.printf "Squeezing page data and xobjects\n%!";
|
close_out fh
|
||||||
squeeze_all_content_streams pdf;
|
in
|
||||||
Printf.printf "Recompressing document\n%!";
|
try
|
||||||
Pdfcodec.flate_level := 9;
|
let n = ref (Pdf.objcard pdf) in
|
||||||
ignore (recompress_pdf pdf)
|
log (Printf.sprintf "Beginning squeeze: %i objects\n" (Pdf.objcard pdf));
|
||||||
with
|
while !n > (ignore (really_squeeze pdf); Pdf.objcard pdf) do
|
||||||
e ->
|
n := Pdf.objcard pdf;
|
||||||
raise
|
log (Printf.sprintf "Squeezing... Down to %i objects\n" (Pdf.objcard pdf));
|
||||||
(Pdf.PDFError
|
done;
|
||||||
(Printf.sprintf
|
log (Printf.sprintf "Squeezing page data and xobjects\n");
|
||||||
"Squeeze failed. No output written.\n Proximate error was:\n %s"
|
squeeze_all_content_streams pdf;
|
||||||
(Printexc.to_string e)))
|
log (Printf.sprintf "Recompressing document\n");
|
||||||
|
Pdfcodec.flate_level := 9;
|
||||||
|
ignore (recompress_pdf pdf)
|
||||||
|
with
|
||||||
|
e ->
|
||||||
|
raise
|
||||||
|
(Pdf.PDFError
|
||||||
|
(Printf.sprintf
|
||||||
|
"Squeeze failed. No output written.\n Proximate error was:\n %s"
|
||||||
|
(Printexc.to_string e)))
|
||||||
|
|
||||||
type encoding =
|
type encoding =
|
||||||
| Raw
|
| Raw
|
||||||
|
|
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