Added -squeeze-no-pagedata, -squeeze-no-recompress
This commit is contained in:
parent
a239cf4edb
commit
35e91e78db
18
cpdf.ml
18
cpdf.ml
|
@ -289,7 +289,7 @@ let squeeze_all_content_streams pdf =
|
||||||
pdf
|
pdf
|
||||||
|
|
||||||
(* We run squeeze enough times for the number of objects to not change *)
|
(* We run squeeze enough times for the number of objects to not change *)
|
||||||
let squeeze ?logto pdf =
|
let squeeze ?logto ?(pagedata=true) ?(recompress=true) pdf =
|
||||||
let log x =
|
let log x =
|
||||||
match logto with
|
match logto with
|
||||||
None -> print_string x; flush stdout
|
None -> print_string x; flush stdout
|
||||||
|
@ -307,11 +307,17 @@ let squeeze ?logto pdf =
|
||||||
n := Pdf.objcard pdf;
|
n := Pdf.objcard pdf;
|
||||||
log (Printf.sprintf "Squeezing... Down to %i objects\n" (Pdf.objcard pdf));
|
log (Printf.sprintf "Squeezing... Down to %i objects\n" (Pdf.objcard pdf));
|
||||||
done;
|
done;
|
||||||
log (Printf.sprintf "Squeezing page data and xobjects\n");
|
if pagedata then
|
||||||
squeeze_all_content_streams pdf;
|
begin
|
||||||
log (Printf.sprintf "Recompressing document\n");
|
log (Printf.sprintf "Squeezing page data and xobjects\n");
|
||||||
Pdfcodec.flate_level := 9;
|
squeeze_all_content_streams pdf;
|
||||||
ignore (recompress_pdf pdf)
|
end;
|
||||||
|
if recompress then
|
||||||
|
begin
|
||||||
|
log (Printf.sprintf "Recompressing document\n");
|
||||||
|
Pdfcodec.flate_level := 9;
|
||||||
|
ignore (recompress_pdf pdf)
|
||||||
|
end
|
||||||
with
|
with
|
||||||
e ->
|
e ->
|
||||||
raise
|
raise
|
||||||
|
|
2
cpdf.mli
2
cpdf.mli
|
@ -425,7 +425,7 @@ val blackfills : float * float * float -> int list -> Pdf.t -> Pdf.t
|
||||||
val draft : string option -> bool -> int list -> Pdf.t -> Pdf.t
|
val draft : string option -> bool -> int list -> Pdf.t -> Pdf.t
|
||||||
|
|
||||||
(** Squeeze a PDF *)
|
(** Squeeze a PDF *)
|
||||||
val squeeze : ?logto:string -> Pdf.t -> unit
|
val squeeze : ?logto:string -> ?pagedata:bool -> ?recompress:bool -> Pdf.t -> unit
|
||||||
|
|
||||||
(**/**)
|
(**/**)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ let demo = false
|
||||||
let noncomp = false
|
let noncomp = false
|
||||||
let major_version = 2
|
let major_version = 2
|
||||||
let minor_version = 4
|
let minor_version = 4
|
||||||
let version_date = "(devel, 30th January 2020)"
|
let version_date = "(devel, 6th May 2020)"
|
||||||
|
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
open Pdfio
|
open Pdfio
|
||||||
|
@ -427,6 +427,8 @@ type args =
|
||||||
mutable labelstartval : int;
|
mutable labelstartval : int;
|
||||||
mutable labelsprogress : bool;
|
mutable labelsprogress : bool;
|
||||||
mutable squeeze : bool;
|
mutable squeeze : bool;
|
||||||
|
mutable squeeze_recompress : bool;
|
||||||
|
mutable squeeze_pagedata: bool;
|
||||||
mutable original_filename : string;
|
mutable original_filename : string;
|
||||||
mutable was_encrypted : bool;
|
mutable was_encrypted : bool;
|
||||||
mutable cpdflin : string option;
|
mutable cpdflin : string option;
|
||||||
|
@ -527,6 +529,8 @@ let args =
|
||||||
labelstartval = 1;
|
labelstartval = 1;
|
||||||
labelsprogress = false;
|
labelsprogress = false;
|
||||||
squeeze = false;
|
squeeze = false;
|
||||||
|
squeeze_recompress = true;
|
||||||
|
squeeze_pagedata = true;
|
||||||
original_filename = "";
|
original_filename = "";
|
||||||
was_encrypted = false;
|
was_encrypted = false;
|
||||||
cpdflin = None;
|
cpdflin = None;
|
||||||
|
@ -642,7 +646,7 @@ let reset_arguments () =
|
||||||
(* Do not reset original_filename or cpdflin or was_encrypted or
|
(* Do not reset original_filename or cpdflin or was_encrypted or
|
||||||
* was_decrypted_with_owner or recrypt or producer or creator or
|
* was_decrypted_with_owner or recrypt or producer or creator or
|
||||||
* path_to_ghostscript or gs_malformed or gs_quiet, since we want these to work across
|
* path_to_ghostscript or gs_malformed or gs_quiet, since we want these to work across
|
||||||
* ANDs. Or squeeze: a little odd, but we want it to happen on eventual output. *)
|
* ANDs. Or squeeze options: a little odd, but we want it to happen on eventual output. *)
|
||||||
|
|
||||||
let get_pagespec () =
|
let get_pagespec () =
|
||||||
match args.inputs with
|
match args.inputs with
|
||||||
|
@ -1490,6 +1494,12 @@ let setocgrenamefrom s =
|
||||||
let setocgrenameto s =
|
let setocgrenameto s =
|
||||||
args.ocgrenameto <- s
|
args.ocgrenameto <- s
|
||||||
|
|
||||||
|
let setsqueezepagedata () =
|
||||||
|
args.squeeze_pagedata <- false
|
||||||
|
|
||||||
|
let setsqueezerecompress () =
|
||||||
|
args.squeeze_recompress <- false
|
||||||
|
|
||||||
let whingemalformed () =
|
let whingemalformed () =
|
||||||
prerr_string "Command line must be of exactly the form\ncpdf <infile> -gs <path> -gs-malformed-force -o <outfile>\n";
|
prerr_string "Command line must be of exactly the form\ncpdf <infile> -gs <path> -gs-malformed-force -o <outfile>\n";
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -2119,6 +2129,8 @@ and specs =
|
||||||
("-gs-quiet", Arg.Unit setgsquiet, " Make gs go into quiet mode");
|
("-gs-quiet", Arg.Unit setgsquiet, " Make gs go into quiet mode");
|
||||||
("-squeeze", Arg.Unit setsqueeze, " Squeeze");
|
("-squeeze", Arg.Unit setsqueeze, " Squeeze");
|
||||||
("-squeeze-log-to", Arg.String setsqueezelogto, " Squeeze log location");
|
("-squeeze-log-to", Arg.String setsqueezelogto, " Squeeze log location");
|
||||||
|
("-squeeze-no-pagedata", Arg.Unit setsqueezepagedata, " Don't recompress pages");
|
||||||
|
("-squeeze-no-recompress", Arg.Unit setsqueezerecompress, " Don't recompress streams");
|
||||||
(* Just for error reporting *)
|
(* Just for error reporting *)
|
||||||
("-gs-malformed-force", Arg.Unit whingemalformed, "");
|
("-gs-malformed-force", Arg.Unit whingemalformed, "");
|
||||||
(* These items are not documented yet, but will be soon *)
|
(* These items are not documented yet, but will be soon *)
|
||||||
|
@ -2513,7 +2525,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 ?logto:!logto pdf;
|
if args.squeeze then Cpdf.squeeze ~pagedata:args.squeeze_pagedata ~recompress:args.squeeze_recompress ?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
|
||||||
|
@ -2529,7 +2541,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 ?logto:!logto pdf;
|
if args.squeeze then Cpdf.squeeze ~pagedata:args.squeeze_pagedata ~recompress:args.squeeze_recompress ?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;
|
||||||
|
@ -2651,7 +2663,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 ?logto:!logto pdf;
|
if sq then Cpdf.squeeze ~pagedata:args.squeeze_pagedata ~recompress:args.squeeze_recompress ?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
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
%Document \n in bookmark files
|
%Document \n in bookmark files
|
||||||
%Document -labels-progress
|
%Document -labels-progress
|
||||||
|
%Document -open-at-page-{fit} now take pagespec not just number
|
||||||
|
%Document -squeeze-no-recompress -squeeze-no-pagedata
|
||||||
\documentclass{book}
|
\documentclass{book}
|
||||||
\usepackage{palatino}
|
\usepackage{palatino}
|
||||||
\usepackage{microtype}
|
\usepackage{microtype}
|
||||||
|
|
Loading…
Reference in New Issue