JSON to outputs

This commit is contained in:
John Whitington 2021-10-01 11:39:47 +01:00
parent d02ff84dd8
commit a6256c0331
7 changed files with 7 additions and 9 deletions

View File

@ -1,6 +1,6 @@
# Build the cpdf command line tools and top level
MODS = cpdfstream tjutil tjutf16 tjllist tjparserMonad tjjson xmlm \
cpdfwriteJSON cpdfreadJSON cpdfstrftime cpdfcoord \
cpdfJSON cpdfstrftime cpdfcoord \
cpdfpagespec cpdfposition cpdf cpdfcommand
SOURCES = $(foreach x,$(MODS),$(x).ml $(x).mli) cpdfcommandrun.ml

View File

@ -232,9 +232,10 @@ let json_of_pdf parse_content no_stream_data pdf =
(fun (objnum, jsonobj) -> J.Array [J.Number (soi objnum); jsonobj])
pairs_parsed)
let write fh parse_content no_stream_data pdf =
(* FIXME Proper streaming to output, rather than making a big string first. *)
let to_output output parse_content no_stream_data pdf =
let b = Buffer.create 256 in
let formatter = Format.formatter_of_buffer b in
J.format formatter (json_of_pdf parse_content no_stream_data pdf);
Format.pp_print_flush formatter ();
output_string fh (Buffer.contents b)
output.Pdfio.output_string (Buffer.contents b)

1
cpdfJSON.mli Normal file
View File

@ -0,0 +1 @@
val to_output : Pdfio.output -> bool -> bool -> Pdf.t -> unit

View File

@ -3447,10 +3447,10 @@ let write_json output pdf =
| NoOutputSpecified ->
error "-output-json: no output name specified"
| Stdout ->
CpdfwriteJSON.write stdout args.jsonparsecontentstreams args.jsonnostreamdata pdf
CpdfJSON.to_output (Pdfio.output_of_channel stdout) args.jsonparsecontentstreams args.jsonnostreamdata pdf
| File filename ->
let f = open_out filename in
CpdfwriteJSON.write f args.jsonparsecontentstreams args.jsonnostreamdata pdf;
CpdfJSON.to_output (Pdfio.output_of_channel f) args.jsonparsecontentstreams args.jsonnostreamdata pdf;
close_out f
(* Main function *)

View File

@ -1,2 +0,0 @@
(* Read JSON into a PDF *)
let read i = Pdf.empty ()

View File

@ -1 +0,0 @@
val read : Pdfio.input -> Pdf.t

View File

@ -1 +0,0 @@
val write : out_channel -> bool -> bool -> Pdf.t -> unit