aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFJob.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-07 01:08:31 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-07 14:26:31 +0200
commita9fbbd5dca1f39e9eafc8ddf8ada30dffd68e4df (patch)
treef5b141539d5972280958b4aa03f9492e17cb4f54 /libqpdf/QPDFJob.cc
parent948de609900745835656d4566a90fee64c5343da (diff)
downloadqpdf-a9fbbd5dca1f39e9eafc8ddf8ada30dffd68e4df.tar.zst
Objectinfo json: write incrementally and in numeric order
This script was used on test data: ---------- #!/usr/bin/env python3 import json import sys import re def json_dumps(data): return json.dumps(data, ensure_ascii=False, indent=2, separators=(',', ': ')) for filename in sys.argv[1:]: with open(filename, 'r') as f: data = json.loads(f.read()) if 'objectinfo' not in data: continue trailer = None to_sort = [] for k, v in data['objectinfo'].items(): if k == 'trailer': trailer = v else: m = re.match(r'^(\d+) \d+ R', k) if m: to_sort.append([int(m.group(1)), k, v]) newobjectinfo = {x[1]: x[2] for x in sorted(to_sort)} if trailer is not None: newobjectinfo['trailer'] = trailer data['objectinfo'] = newobjectinfo print(json_dumps(data)) ----------
Diffstat (limited to 'libqpdf/QPDFJob.cc')
-rw-r--r--libqpdf/QPDFJob.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc
index 63fa0c34..78c678b0 100644
--- a/libqpdf/QPDFJob.cc
+++ b/libqpdf/QPDFJob.cc
@@ -1066,13 +1066,14 @@ QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf)
void
QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf)
{
+ JSON::writeDictionaryKey(p, first, "objectinfo", 0);
+ bool first_object = true;
+ JSON::writeDictionaryOpen(p, first_object, 1);
bool all_objects = m->json_objects.empty();
std::set<QPDFObjGen> wanted_og = getWantedJSONObjects();
- JSON j_objectinfo = JSON::makeDictionary();
for (auto& obj: pdf.getAllObjects()) {
if (all_objects || wanted_og.count(obj.getObjGen())) {
- auto j_details = j_objectinfo.addDictionaryMember(
- obj.unparse(), JSON::makeDictionary());
+ auto j_details = JSON::makeDictionary();
auto j_stream =
j_details.addDictionaryMember("stream", JSON::makeDictionary());
bool is_stream = obj.isStream();
@@ -1085,9 +1086,11 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf)
"filter",
(is_stream ? obj.getDict().getKey("/Filter").getJSON(true)
: JSON::makeNull()));
+ JSON::writeDictionaryItem(
+ p, first_object, obj.unparse(), j_details, 1);
}
}
- JSON::writeDictionaryItem(p, first, "objectinfo", j_objectinfo, 0);
+ JSON::writeDictionaryClose(p, first_object, 1);
}
void