This commit is contained in:
John Whitington 2021-10-12 19:52:03 +01:00
parent 2859f9e4ef
commit fff0e7e6e3
2 changed files with 15 additions and 12 deletions

View File

@ -1,5 +1,6 @@
2.5 (Upcoming 2022) 2.5 (Upcoming 2022)
o -debug-force now properly documented as -decrypt-force
o Switch to Yojson o Switch to Yojson
o Can read as well as write PDFs in JSON format with -j o Can read as well as write PDFs in JSON format with -j
o Environment variable CPDF_REPRODUCIBLE_DATES for testing o Environment variable CPDF_REPRODUCIBLE_DATES for testing

View File

@ -94,9 +94,9 @@ let rec op_of_json = function
| `List torev -> | `List torev ->
begin match rev torev with begin match rev torev with
| `String "SCN"::ns -> O.Op_SCN (map opf (rev ns)) | `String "SCN"::ns -> O.Op_SCN (map opf (rev ns))
| `String "SC"::ns -> O.Op_SCN (map opf (rev ns)) | `String "SC"::ns -> O.Op_SC (map opf (rev ns))
| `String "sc"::ns -> O.Op_SCN (map opf (rev ns)) | `String "sc"::ns -> O.Op_sc (map opf (rev ns))
| `String "scn"::ns -> O.Op_SCN (map opf (rev ns)) | `String "scn"::ns -> O.Op_scn (map opf (rev ns))
| `String "SCNName"::`String s::ns -> O.Op_SCNName (s, map opf (rev ns)) | `String "SCNName"::`String s::ns -> O.Op_SCNName (s, map opf (rev ns))
| `String "scnName"::`String s::ns -> O.Op_scnName (s, map opf (rev ns)) | `String "scnName"::`String s::ns -> O.Op_scnName (s, map opf (rev ns))
| j -> | j ->
@ -413,16 +413,18 @@ let json_of_pdf
(fun (objnum, jsonobj) -> `List [`Int objnum; jsonobj]) (fun (objnum, jsonobj) -> `List [`Int objnum; jsonobj])
pairs_parsed) pairs_parsed)
(* FIXME Proper streaming to output *)
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 ~precombine_page_content 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 ~precombine_page_content pdf in
o.Pdfio.output_string (J.pretty_to_string json) match o.Pdfio.out_caml_channel with
| Some ch -> J.pretty_to_channel ch json
| None -> o.Pdfio.output_string (J.pretty_to_string json)
(* FIXME Proper streaming to output / from input, rather than making a big string first. *)
let of_input i = let of_input i =
let content = Pdfio.string_of_bytes (Pdfio.bytes_of_input i 0 (i.Pdfio.in_channel_length)) in try
let json = match i.Pdfio.caml_channel with
try J.from_string content with | Some ch -> pdf_of_json (J.from_channel ch)
e -> error (Printexc.to_string e) | None ->
in let content = Pdfio.string_of_bytes (Pdfio.bytes_of_input i 0 (i.Pdfio.in_channel_length)) in
pdf_of_json json pdf_of_json (J.from_string content)
with
e -> error (Printexc.to_string e)