From bb96499b613265b3d9cf2146af09283a4b99ef13 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 24 Jul 2022 16:54:48 -0400 Subject: Update docs and prepare QPDF::writeJSON for changes Add additional parameters that will be needed to call QPDF::writeJSON in partial mode. --- libqpdf/QPDFJob.cc | 2 ++ libqpdf/QPDFJob_config.cc | 3 +++ libqpdf/QPDF_json.cc | 10 +++++++--- libqpdf/qpdf/auto_job_help.hh | 16 +++++++++------- 4 files changed, 21 insertions(+), 10 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 06e93704..ae717218 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -3381,6 +3381,8 @@ QPDFJob::writeJSON(QPDF& pdf) pdf.writeJSON( this->m->json_output, fp.get(), + true, + true, this->m->decode_level, this->m->json_stream_data, file_prefix, diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index 0192346e..6a500b5c 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -312,6 +312,9 @@ QPDFJob::Config::jsonOutput(std::string const& parameter) if (!o.m->decode_level_set) { o.m->decode_level = qpdf_dl_none; } + if (o.m->json_keys.empty()) { + o.m->json_keys.insert("qpdf"); + } return this; } diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 59aac05e..81f21f8a 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -764,6 +764,8 @@ void QPDF::writeJSON( int version, Pipeline* p, + bool complete, + bool first_key, qpdf_stream_decode_level_e decode_level, qpdf_json_stream_data_e json_stream_data, std::string const& file_prefix, @@ -818,7 +820,9 @@ QPDF::writeJSON( } JSON::writeDictionaryClose(p, first_object, 2); JSON::writeDictionaryClose(p, first_qpdf, 1); - JSON::writeDictionaryClose(p, first, 0); - *p << "\n"; - p->finish(); + if (complete) { + JSON::writeDictionaryClose(p, first, 0); + *p << "\n"; + p->finish(); + } } diff --git a/libqpdf/qpdf/auto_job_help.hh b/libqpdf/qpdf/auto_job_help.hh index 5146ddae..6ade99f5 100644 --- a/libqpdf/qpdf/auto_job_help.hh +++ b/libqpdf/qpdf/auto_job_help.hh @@ -821,16 +821,18 @@ objects will be shown. )"); ap.addOptionHelp("--json-stream-data", "json", "how to handle streams in json output", R"(--json-stream-data={none|inline|file} -When used with --json-output, this option controls whether -streams in json output should be omitted, written inline -(base64-encoded) or written to a file. If "file" is chosen, the -file will be the name of the output file appended with -nnn where -nnn is the object number. The prefix can be overridden with ---json-stream-prefix. +When used with --json, this option controls whether streams in +json output should be omitted, written inline (base64-encoded) +or written to a file. If "file" is chosen, the file will be the +name of the output file appended with -nnn where nnn is the +object number. The prefix can be overridden with +--json-stream-prefix. The default is "none", except +when --json-output is specified, in which case the default is +"inline". )"); ap.addOptionHelp("--json-stream-prefix", "json", "prefix for json stream data files", R"(--json-stream-prefix=file-prefix -When used with --json-output, --json-stream-data=file-prefix +When used with --json-stream-data=file, --json-stream-data=file-prefix sets the prefix for stream data files, overriding the default, which is to use the output file name. Whatever is given here will be appended with -nnn to create the name of the file that -- cgit v1.2.3-54-g00ecf