From 19633c9019361a6b5098431ce3a60fb74c5dbb89 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 5 Oct 2021 13:08:46 +0100 Subject: [PATCH] Fix up /Length --- cpdfjson.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cpdfjson.ml b/cpdfjson.ml index 4e1eaef..9c6f1ac 100644 --- a/cpdfjson.ml +++ b/cpdfjson.ml @@ -120,7 +120,11 @@ and object_of_json = function | J.Object ["F", J.Number f] -> P.Real (float_of_string f) | J.Object ["N", J.String n] -> P.Name n | J.Object ["S", J.Array [dict; J.String data]] -> - P.Stream (ref (object_of_json dict, P.Got (Pdfio.bytes_of_string data))) + (* Fix up the length, in case it's been edited. *) + let d' = + P.add_dict_entry (object_of_json dict) "/Length" (P.Integer (String.length data)) + in + P.Stream (ref (d', P.Got (Pdfio.bytes_of_string data))) | J.Object ["S", J.Array [dict; J.Array parsed_ops]] -> Pdfops.stream_of_ops (List.map op_of_json parsed_ops) | J.Object elts -> P.Dictionary (map (fun (n, o) -> (n, object_of_json o)) elts)