Fixed -squeeze-log-to bug

This commit is contained in:
John Whitington 2019-08-16 15:16:21 +01:00
parent 9054a246ae
commit 3807738491
4 changed files with 27 additions and 7 deletions

View File

@ -2280,12 +2280,14 @@ let change_pattern_matrices_page pdf tr page =
(* Apply transformations to any annotations in /Annots (i.e their /Rect entries) *)
let transform_annotations pdf transform rest =
(*Printf.printf "in transform_annotations\n";*)
match Pdf.lookup_direct pdf "/Annots" rest with
| Some (Pdf.Array annots) ->
(* Always indirect references, so alter in place *)
List.iter
(function
| Pdf.Indirect i ->
(*Printf.printf "Found an annotation to modify...\n";*)
let annot = Pdf.lookup_obj pdf i in
let rect' =
match Pdf.lookup_direct pdf "/Rect" annot with

View File

@ -2462,6 +2462,12 @@ let get_single_pdf_nodecrypt read_lazy =
let filenames = null_hash ()
let squeeze_logto filename x =
let fh = open_out_gen [Open_wronly; Open_creat] 0o666 filename in
seek_out fh (out_channel_length fh);
output_string fh x;
close_out fh
(* This now memoizes on the name of the file to make sure we only load each
file once *)
let rec get_pdf_from_input_kind ?(read_lazy=false) ?(decrypt=true) ?(fail=false) ((_, x, u, o, y, revision) as input) op ik =
@ -2491,7 +2497,11 @@ let rec get_pdf_from_input_kind ?(read_lazy=false) ?(decrypt=true) ?(fail=false)
begin
let size = filesize s in
initial_file_size := size;
if !logto = None then Printf.printf "Initial file size is %i bytes\n" size
let str = Printf.sprintf "Initial file size is %i bytes\n" size in
begin match !logto with
| None -> print_string str
| Some filename -> squeeze_logto filename str
end
end;
begin try Hashtbl.find filenames s with
Not_found ->
@ -2635,11 +2645,17 @@ let really_write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf outna
end;
if args.squeeze then
let s = filesize outname in
if !logto = None then
Printf.printf
"Final file size is %i bytes, %.2f%% of original.\n"
s
((float s /. float !initial_file_size) *. 100.)
begin
let str =
Printf.sprintf
"Final file size is %i bytes, %.2f%% of original.\n"
s
((float s /. float !initial_file_size) *. 100.)
in
match !logto with
| None -> print_string str
| Some filename -> squeeze_logto filename str
end
let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf =
if args.debugcrypt then Printf.printf "write_pdf\n";

Binary file not shown.

View File

@ -1124,14 +1124,16 @@ PDF, use:
\begin{verbatim}
$ ./cpdf -squeeze in.pdf -o out.pdf
Initial file size is 238169 bytes
Beginning squeeze: 123847 objects
Squeezing... Down to 114860 objects
Squeezing... Down to 114842 objects
Squeezing page data
Recompressing document
Final file size is 187200 bytes, 78.60% of original.
\end{verbatim}
\noindent The \texttt{-squeeze-log-to <filename>} option writes the log to the given file instead of to standard output.
\noindent The \texttt{-squeeze-log-to <filename>} option writes the log to the given file instead of to standard output. Log contents is appended to the end of the log file, preserving existing contents.
\chapter{Bookmarks}
\begin{framed}