Yojson in
This commit is contained in:
parent
e29e7b3038
commit
86e0ce6f2f
2
Changes
2
Changes
|
@ -1,6 +1,6 @@
|
|||
2.5 (Upcoming 2022)
|
||||
|
||||
o Vendored in camlp-streams module before deprecation
|
||||
o Switch to Yojson
|
||||
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_DEBUG for -debug
|
||||
|
|
4
Makefile
4
Makefile
|
@ -1,6 +1,6 @@
|
|||
# Build the cpdf command line tools and top level
|
||||
MODS = cpdfstream tjutil tjutf16 tjllist tjparsermonad tjjson \
|
||||
xmlm cpdferror cpdfjson cpdfstrftime cpdfcoord cpdfattach \
|
||||
MODS = cpdfyojson cpdfstream tjutil tjutf16 tjllist tjparsermonad tjjson \
|
||||
cpdfxmlm cpdferror cpdfjson cpdfstrftime cpdfcoord cpdfattach \
|
||||
cpdfpagespec cpdfposition cpdf cpdfcommand
|
||||
|
||||
SOURCES = $(foreach x,$(MODS),$(x).ml $(x).mli) cpdfcommandrun.ml
|
||||
|
|
10
cpdf.ml
10
cpdf.ml
|
@ -2986,23 +2986,23 @@ let output_info encoding pdf =
|
|||
Printf.printf "Trapped: %s\n" (getstring "/Trapped")
|
||||
|
||||
type xmltree =
|
||||
E of Xmlm.tag * xmltree list
|
||||
E of Cpdfxmlm.tag * xmltree list
|
||||
| D of string
|
||||
|
||||
let xmltree_of_bytes b =
|
||||
let i = Xmlm.make_input (`String (0, string_of_bytes b)) in
|
||||
let i = Cpdfxmlm.make_input (`String (0, string_of_bytes b)) in
|
||||
let el tag childs = E (tag, childs)
|
||||
and data d = D d in
|
||||
Xmlm.input_doc_tree ~el ~data i
|
||||
Cpdfxmlm.input_doc_tree ~el ~data i
|
||||
|
||||
let bytes_of_xmltree t =
|
||||
let buf = Buffer.create 1024 in
|
||||
let o = Xmlm.make_output (`Buffer buf) in
|
||||
let o = Cpdfxmlm.make_output (`Buffer buf) in
|
||||
let frag = function
|
||||
E (tag, childs) -> `El (tag, childs)
|
||||
| D d -> `Data d
|
||||
in
|
||||
Xmlm.output_doc_tree frag o t;
|
||||
Cpdfxmlm.output_doc_tree frag o t;
|
||||
bytes_of_string (Buffer.contents buf)
|
||||
|
||||
let rec string_of_xmltree = function
|
||||
|
|
13
cpdfjson.ml
13
cpdfjson.ml
|
@ -426,6 +426,17 @@ let to_output o parse_content no_stream_data decompress_streams pdf =
|
|||
Format.pp_print_flush formatter ();
|
||||
o.Pdfio.output_string (Buffer.contents b)
|
||||
|
||||
let example_pdf =
|
||||
let page =
|
||||
{(Pdfpage.blankpage Pdfpaper.a4) with
|
||||
Pdfpage.content = [Pdfops.stream_of_ops []];
|
||||
Pdfpage.resources = Pdf.Dictionary []}
|
||||
in
|
||||
let pdf, pageroot = Pdfpage.add_pagetree (many page 1) (Pdf.empty ()) in
|
||||
Pdfpage.add_root pageroot [] pdf
|
||||
|
||||
(* FIXME Proper streaming to output / from input, rather than making a big string first. *)
|
||||
let of_input i =
|
||||
pdf_of_json (J.parse (Pdfio.string_of_bytes (Pdfio.bytes_of_input i 0 (i.Pdfio.in_channel_length))))
|
||||
(*pdf_of_json*)
|
||||
ignore (J.parse (Pdfio.string_of_bytes (Pdfio.bytes_of_input i 0 (i.Pdfio.in_channel_length))));
|
||||
example_pdf
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue