This commit is contained in:
John Whitington 2021-10-14 20:28:43 +01:00
parent b6a0c04644
commit a0ca312f6e
3 changed files with 10 additions and 21 deletions

View File

@ -449,7 +449,6 @@ type args =
mutable createpdf_pagesize : Pdfpaper.t; mutable createpdf_pagesize : Pdfpaper.t;
mutable removeonly : string option; mutable removeonly : string option;
mutable jsonparsecontentstreams : bool; mutable jsonparsecontentstreams : bool;
mutable jsonprecombinecontentstreams : bool;
mutable jsonnostreamdata : bool; mutable jsonnostreamdata : bool;
mutable jsondecompressstreams : bool; mutable jsondecompressstreams : bool;
mutable ocgrenamefrom : string; mutable ocgrenamefrom : string;
@ -555,7 +554,6 @@ let args =
createpdf_pagesize = Pdfpaper.a4; createpdf_pagesize = Pdfpaper.a4;
removeonly = None; removeonly = None;
jsonparsecontentstreams = false; jsonparsecontentstreams = false;
jsonprecombinecontentstreams = false;
jsonnostreamdata = false; jsonnostreamdata = false;
jsondecompressstreams = false; jsondecompressstreams = false;
ocgrenamefrom = ""; ocgrenamefrom = "";
@ -646,7 +644,6 @@ let reset_arguments () =
args.createpdf_pagesize <- Pdfpaper.a4; args.createpdf_pagesize <- Pdfpaper.a4;
args.removeonly <- None; args.removeonly <- None;
args.jsonparsecontentstreams <- false; args.jsonparsecontentstreams <- false;
args.jsonprecombinecontentstreams <- false;
args.jsonnostreamdata <- false; args.jsonnostreamdata <- false;
args.jsondecompressstreams <- false; args.jsondecompressstreams <- false;
args.ocgrenamefrom <- ""; args.ocgrenamefrom <- "";
@ -1502,9 +1499,6 @@ let setgsquiet () =
let setjsonparsecontentstreams () = let setjsonparsecontentstreams () =
args.jsonparsecontentstreams <- true args.jsonparsecontentstreams <- true
let setjsonprecombinecontentstreams () =
args.jsonprecombinecontentstreams <- true
let setjsonnostreamdata () = let setjsonnostreamdata () =
args.jsonnostreamdata <- true args.jsonnostreamdata <- true
@ -2199,9 +2193,6 @@ and specs =
("-output-json-parse-content-streams", ("-output-json-parse-content-streams",
Arg.Unit setjsonparsecontentstreams, Arg.Unit setjsonparsecontentstreams,
" Parse content streams"); " Parse content streams");
("-output-json-precombine-content-streams",
Arg.Unit setjsonprecombinecontentstreams,
" Precombine content streams");
("-output-json-no-stream-data", ("-output-json-no-stream-data",
Arg.Unit setjsonnostreamdata, Arg.Unit setjsonnostreamdata,
" Skip stream data for brevity"); " Skip stream data for brevity");
@ -3417,7 +3408,6 @@ let write_json output pdf =
~parse_content:args.jsonparsecontentstreams ~parse_content:args.jsonparsecontentstreams
~no_stream_data:args.jsonnostreamdata ~no_stream_data:args.jsonnostreamdata
~decompress_streams:args.jsondecompressstreams ~decompress_streams:args.jsondecompressstreams
~precombine_page_content:args.jsonprecombinecontentstreams
pdf pdf
| File filename -> | File filename ->
let f = open_out filename in let f = open_out filename in
@ -3426,7 +3416,6 @@ let write_json output pdf =
~parse_content:args.jsonparsecontentstreams ~parse_content:args.jsonparsecontentstreams
~no_stream_data:args.jsonnostreamdata ~no_stream_data:args.jsonnostreamdata
~decompress_streams:args.jsondecompressstreams ~decompress_streams:args.jsondecompressstreams
~precombine_page_content:args.jsonprecombinecontentstreams
pdf; pdf;
close_out f close_out f

View File

@ -287,10 +287,10 @@ let json_of_op pdf no_stream_data = function
| O.Op_M m -> `List [mkfloat m; `String "M"] | O.Op_M m -> `List [mkfloat m; `String "M"]
| O.Op_ri s -> `List [`String s; `String "ri"] | O.Op_ri s -> `List [`String s; `String "ri"]
| O.Op_i i -> `List [mkint i; `String "i"] | O.Op_i i -> `List [mkint i; `String "i"]
| O.Op_c (a, b, c, d, e, k) -> | O.Op_c (a, b, c, d, e, f) ->
`List `List
[mkfloat a; mkfloat b; mkfloat c; [mkfloat a; mkfloat b; mkfloat c;
mkfloat d; mkfloat e; mkfloat k; `String "c"] mkfloat d; mkfloat e; mkfloat f; `String "c"]
| O.Op_v (a, b, c, d) -> | O.Op_v (a, b, c, d) ->
`List `List
[mkfloat a; mkfloat b; mkfloat c; [mkfloat a; mkfloat b; mkfloat c;
@ -318,10 +318,10 @@ let json_of_op pdf no_stream_data = function
| O.Op_' s -> `List [`String s; `String "'"] | O.Op_' s -> `List [`String s; `String "'"]
| O.Op_'' (k, k', s) -> `List [mkfloat k; mkfloat k'; `String s; `String "''"] | O.Op_'' (k, k', s) -> `List [mkfloat k; mkfloat k'; `String s; `String "''"]
| O.Op_d0 (k, k') -> `List [mkfloat k; mkfloat k'; `String "d0"] | O.Op_d0 (k, k') -> `List [mkfloat k; mkfloat k'; `String "d0"]
| O.Op_d1 (a, b, c, d, e, k) -> | O.Op_d1 (a, b, c, d, e, f) ->
`List `List
[mkfloat a; mkfloat b; mkfloat c; [mkfloat a; mkfloat b; mkfloat c;
mkfloat d; mkfloat e; mkfloat k; `String "d1"] mkfloat d; mkfloat e; mkfloat f; `String "d1"]
| O.Op_cs s -> `List [`String s; `String "cs"] | O.Op_cs s -> `List [`String s; `String "cs"]
| O.Op_SC fs -> `List (map (fun x -> mkfloat x) fs @ [`String "SC"]) | O.Op_SC fs -> `List (map (fun x -> mkfloat x) fs @ [`String "SC"])
| O.Op_sc fs -> `List (map (fun x -> mkfloat x) fs @ [`String "sc"]) | O.Op_sc fs -> `List (map (fun x -> mkfloat x) fs @ [`String "sc"])
@ -354,7 +354,7 @@ let parse_content_stream pdf resources bs =
if not split on op boundaries, each one would fail to parse on its own. The if not split on op boundaries, each one would fail to parse on its own. The
caller should really only do this on otherwise-failing files, since it could caller should really only do this on otherwise-failing files, since it could
blow up any shared content streams. *) blow up any shared content streams. *)
let do_precombine_page_content pdf = let precombine_page_content pdf =
let pages' = let pages' =
map map
(fun page -> (fun page ->
@ -371,10 +371,10 @@ let do_precombine_page_content pdf =
Pdfpage.change_pages true pdf pages' Pdfpage.change_pages true pdf pages'
let json_of_pdf let json_of_pdf
~parse_content ~no_stream_data ~decompress_streams ~precombine_page_content ~parse_content ~no_stream_data ~decompress_streams
pdf pdf
= =
let pdf = if parse_content && precombine_page_content then do_precombine_page_content pdf else pdf in let pdf = if parse_content then precombine_page_content pdf else pdf in
if decompress_streams then if decompress_streams then
Pdf.objiter (fun _ obj -> Pdfcodec.decode_pdfstream_until_unknown pdf obj) pdf; Pdf.objiter (fun _ obj -> Pdfcodec.decode_pdfstream_until_unknown pdf obj) pdf;
Pdf.remove_unreferenced pdf; Pdf.remove_unreferenced pdf;
@ -432,8 +432,8 @@ let json_of_pdf
(fun (objnum, jsonobj) -> `List [`Int objnum; jsonobj]) (fun (objnum, jsonobj) -> `List [`Int objnum; jsonobj])
pairs_parsed) pairs_parsed)
let to_output o ~parse_content ~no_stream_data ~decompress_streams ~precombine_page_content pdf = let to_output o ~parse_content ~no_stream_data ~decompress_streams pdf =
let json = json_of_pdf ~parse_content ~no_stream_data ~decompress_streams ~precombine_page_content pdf in let json = json_of_pdf ~parse_content ~no_stream_data ~decompress_streams pdf in
match o.Pdfio.out_caml_channel with match o.Pdfio.out_caml_channel with
| Some ch -> J.pretty_to_channel ch json | Some ch -> J.pretty_to_channel ch json
| None -> o.Pdfio.output_string (J.pretty_to_string json) | None -> o.Pdfio.output_string (J.pretty_to_string json)

View File

@ -1,2 +1,2 @@
val to_output : Pdfio.output -> parse_content:bool -> no_stream_data:bool -> decompress_streams:bool -> precombine_page_content:bool -> Pdf.t -> unit val to_output : Pdfio.output -> parse_content:bool -> no_stream_data:bool -> decompress_streams:bool -> Pdf.t -> unit
val of_input : Pdfio.input -> Pdf.t val of_input : Pdfio.input -> Pdf.t