diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-05-19 00:22:57 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-05-20 15:16:25 +0200 |
commit | 6f43bf8de36b08c55b172b4f4133c79657651666 (patch) | |
tree | ec17bbf42d9ea78d44ab3b9d2cac363cc6b9bc68 /libqpdf/qpdf | |
parent | 23fc6756f1894e1af35853eb2251f08d5b25cf30 (diff) | |
download | qpdf-6f43bf8de36b08c55b172b4f4133c79657651666.tar.zst |
Major rework -- see long comments
* Replace --create-from-json=file with --json-input, which causes the
regular input to be treated as json.
* Eliminate --to-json
* In --json=2, bring back "objects" and eliminate "objectinfo". Stream
data is never present.
* In --json-output=2, write "qpdf-v2" with "objects" and include
stream data.
Diffstat (limited to 'libqpdf/qpdf')
-rw-r--r-- | libqpdf/qpdf/auto_job_decl.hh | 1 | ||||
-rw-r--r-- | libqpdf/qpdf/auto_job_help.hh | 17 | ||||
-rw-r--r-- | libqpdf/qpdf/auto_job_init.hh | 11 | ||||
-rw-r--r-- | libqpdf/qpdf/auto_job_json_decl.hh | 1 | ||||
-rw-r--r-- | libqpdf/qpdf/auto_job_json_init.hh | 17 | ||||
-rw-r--r-- | libqpdf/qpdf/auto_job_schema.hh | 4 |
6 files changed, 26 insertions, 25 deletions
diff --git a/libqpdf/qpdf/auto_job_decl.hh b/libqpdf/qpdf/auto_job_decl.hh index 8c656986..02f0ca91 100644 --- a/libqpdf/qpdf/auto_job_decl.hh +++ b/libqpdf/qpdf/auto_job_decl.hh @@ -28,7 +28,6 @@ void argOverlay(); void argPages(); void argReplaceInput(); void argUnderlay(); -void argCreateFromJson(std::string const&); void argPagesPositional(std::string const&); void argPagesPassword(std::string const&); void argEndPages(); diff --git a/libqpdf/qpdf/auto_job_help.hh b/libqpdf/qpdf/auto_job_help.hh index e17412d0..7d88155b 100644 --- a/libqpdf/qpdf/auto_job_help.hh +++ b/libqpdf/qpdf/auto_job_help.hh @@ -798,10 +798,6 @@ depth in the JSON section of the manual. "version" may be a specific version or "latest". Run qpdf --json-help for a description of the generated JSON object. )"); -ap.addOptionHelp("--to-json", "json", "serialize to JSON", R"(Shortcut for options useful for serializing PDF to JSON: ---json=latest --json-stream-data=inline - --json-key=qpdf --decode-level=none -)"); ap.addOptionHelp("--json-help", "json", "show format of JSON output", R"(Describe the format of the JSON output by writing to standard output a JSON object with the same keys and with values containing descriptive text. @@ -836,11 +832,16 @@ name as the prefix for stream data files. Whatever is given here will be appended with -nnn to create the name of the file that will contain the data for the stream stream in object nnn. )"); -ap.addOptionHelp("--create-from-json", "json", "create PDF from qpdf JSON", R"(--create-from-json=qpdf-json-file +ap.addOptionHelp("--json-output", "json", "serialize to JSON", R"(--json-output=version -Create a PDF file from the prior output of qpdf --json. See the -"QPDF JSON Format" section of the manual for information about -how to use this option. +The output file will be qpdf JSON format at the given version. +Only version 2 is supported. See also --json-stream-data +and --json-stream-prefix +)"); +ap.addOptionHelp("--json-input", "json", "input file is qpdf JSON", R"(Treat the input file as a JSON file in qpdf JSON format as +written by qpdf --json-output. See the "QPDF JSON Format" +section of the manual for information about how to use this +option. )"); ap.addOptionHelp("--update-from-json", "json", "update a PDF from qpdf JSON", R"(--update-from-json=qpdf-json-file diff --git a/libqpdf/qpdf/auto_job_init.hh b/libqpdf/qpdf/auto_job_init.hh index 9446811f..f582c6ec 100644 --- a/libqpdf/qpdf/auto_job_init.hh +++ b/libqpdf/qpdf/auto_job_init.hh @@ -19,9 +19,10 @@ static char const* decode_level_choices[] = {"none", "generalized", "specialized static char const* object_streams_choices[] = {"disable", "preserve", "generate", 0}; static char const* remove_unref_choices[] = {"auto", "yes", "no", 0}; static char const* flatten_choices[] = {"all", "print", "screen", 0}; -static char const* json_version_choices[] = {"1", "2", "latest", 0}; -static char const* json_key_choices[] = {"acroform", "attachments", "encrypt", "objectinfo", "objects", "outlines", "pagelabels", "pages", "qpdf", 0}; +static char const* json_key_choices[] = {"acroform", "attachments", "encrypt", "objectinfo", "objects", "outlines", "pagelabels", "pages", 0}; +static char const* json_output_choices[] = {"2", "latest", 0}; static char const* json_stream_data_choices[] = {"none", "inline", "file", 0}; +static char const* json_version_choices[] = {"1", "2", "latest", 0}; static char const* print128_choices[] = {"full", "low", "none", 0}; static char const* modify128_choices[] = {"all", "annotate", "form", "assembly", "none", 0}; @@ -49,6 +50,7 @@ this->ap.addBare("flatten-rotation", [this](){c_main->flattenRotation();}); this->ap.addBare("generate-appearances", [this](){c_main->generateAppearances();}); this->ap.addBare("ignore-xref-streams", [this](){c_main->ignoreXrefStreams();}); this->ap.addBare("is-encrypted", [this](){c_main->isEncrypted();}); +this->ap.addBare("json-input", [this](){c_main->jsonInput();}); this->ap.addBare("keep-inline-images", [this](){c_main->keepInlineImages();}); this->ap.addBare("linearize", [this](){c_main->linearize();}); this->ap.addBare("list-attachments", [this](){c_main->listAttachments();}); @@ -79,7 +81,6 @@ this->ap.addBare("static-id", [this](){c_main->staticId();}); this->ap.addBare("suppress-password-recovery", [this](){c_main->suppressPasswordRecovery();}); this->ap.addBare("suppress-recovery", [this](){c_main->suppressRecovery();}); this->ap.addBare("test-json-schema", [this](){c_main->testJsonSchema();}); -this->ap.addBare("to-json", [this](){c_main->toJson();}); this->ap.addBare("underlay", b(&ArgParser::argUnderlay)); this->ap.addBare("verbose", [this](){c_main->verbose();}); this->ap.addBare("warning-exit-0", [this](){c_main->warningExit0();}); @@ -104,7 +105,6 @@ this->ap.addRequiredParameter("rotate", [this](std::string const& x){c_main->rot this->ap.addRequiredParameter("show-attachment", [this](std::string const& x){c_main->showAttachment(x);}, "attachment"); this->ap.addRequiredParameter("show-object", [this](std::string const& x){c_main->showObject(x);}, "trailer"); this->ap.addRequiredParameter("json-stream-prefix", [this](std::string const& x){c_main->jsonStreamPrefix(x);}, "stream-file-prefix"); -this->ap.addRequiredParameter("create-from-json", p(&ArgParser::argCreateFromJson), "qpdf-json file"); this->ap.addRequiredParameter("update-from-json", [this](std::string const& x){c_main->updateFromJson(x);}, "qpdf-json file"); this->ap.addOptionalParameter("collate", [this](std::string const& x){c_main->collate(x);}); this->ap.addOptionalParameter("split-pages", [this](std::string const& x){c_main->splitPages(x);}); @@ -112,13 +112,14 @@ this->ap.addChoices("compress-streams", [this](std::string const& x){c_main->com this->ap.addChoices("decode-level", [this](std::string const& x){c_main->decodeLevel(x);}, true, decode_level_choices); this->ap.addChoices("flatten-annotations", [this](std::string const& x){c_main->flattenAnnotations(x);}, true, flatten_choices); this->ap.addChoices("json-key", [this](std::string const& x){c_main->jsonKey(x);}, true, json_key_choices); +this->ap.addChoices("json-output", [this](std::string const& x){c_main->jsonOutput(x);}, true, json_output_choices); +this->ap.addChoices("json-stream-data", [this](std::string const& x){c_main->jsonStreamData(x);}, true, json_stream_data_choices); this->ap.addChoices("keep-files-open", [this](std::string const& x){c_main->keepFilesOpen(x);}, true, yn_choices); this->ap.addChoices("normalize-content", [this](std::string const& x){c_main->normalizeContent(x);}, true, yn_choices); this->ap.addChoices("object-streams", [this](std::string const& x){c_main->objectStreams(x);}, true, object_streams_choices); this->ap.addChoices("password-mode", [this](std::string const& x){c_main->passwordMode(x);}, true, password_mode_choices); this->ap.addChoices("remove-unreferenced-resources", [this](std::string const& x){c_main->removeUnreferencedResources(x);}, true, remove_unref_choices); this->ap.addChoices("stream-data", [this](std::string const& x){c_main->streamData(x);}, true, stream_data_choices); -this->ap.addChoices("json-stream-data", [this](std::string const& x){c_main->jsonStreamData(x);}, true, json_stream_data_choices); this->ap.addChoices("json", [this](std::string const& x){c_main->json(x);}, false, json_version_choices); this->ap.registerOptionTable("pages", b(&ArgParser::argEndPages)); this->ap.addPositional(p(&ArgParser::argPagesPositional)); diff --git a/libqpdf/qpdf/auto_job_json_decl.hh b/libqpdf/qpdf/auto_job_json_decl.hh index 8160ca5a..f02dc657 100644 --- a/libqpdf/qpdf/auto_job_json_decl.hh +++ b/libqpdf/qpdf/auto_job_json_decl.hh @@ -8,7 +8,6 @@ void setupInputFile(); void setupPassword(); void setupEmpty(); -void setupCreateFromJson(); void setupOutputFile(); void setupReplaceInput(); void beginEncrypt(JSON); diff --git a/libqpdf/qpdf/auto_job_json_init.hh b/libqpdf/qpdf/auto_job_json_init.hh index ee124d0d..125250e6 100644 --- a/libqpdf/qpdf/auto_job_json_init.hh +++ b/libqpdf/qpdf/auto_job_json_init.hh @@ -12,9 +12,10 @@ static char const* decode_level_choices[] = {"none", "generalized", "specialized static char const* object_streams_choices[] = {"disable", "preserve", "generate", 0}; static char const* remove_unref_choices[] = {"auto", "yes", "no", 0}; static char const* flatten_choices[] = {"all", "print", "screen", 0}; -static char const* json_version_choices[] = {"1", "2", "latest", 0}; -static char const* json_key_choices[] = {"acroform", "attachments", "encrypt", "objectinfo", "objects", "outlines", "pagelabels", "pages", "qpdf", 0}; +static char const* json_key_choices[] = {"acroform", "attachments", "encrypt", "objectinfo", "objects", "outlines", "pagelabels", "pages", 0}; +static char const* json_output_choices[] = {"2", "latest", 0}; static char const* json_stream_data_choices[] = {"none", "inline", "file", 0}; +static char const* json_version_choices[] = {"1", "2", "latest", 0}; static char const* print128_choices[] = {"full", "low", "none", 0}; static char const* modify128_choices[] = {"all", "annotate", "form", "assembly", "none", 0}; @@ -30,9 +31,9 @@ popHandler(); // key: passwordFile pushKey("empty"); setupEmpty(); popHandler(); // key: empty -pushKey("createFromJson"); -setupCreateFromJson(); -popHandler(); // key: createFromJson +pushKey("jsonInput"); +addBare([this]() { c_main->jsonInput(); }); +popHandler(); // key: jsonInput pushKey("outputFile"); setupOutputFile(); popHandler(); // key: outputFile @@ -105,6 +106,9 @@ popHandler(); // key: progress pushKey("splitPages"); addParameter([this](std::string const& p) { c_main->splitPages(p); }); popHandler(); // key: splitPages +pushKey("jsonOutput"); +addChoices(json_output_choices, true, [this](std::string const& p) { c_main->jsonOutput(p); }); +popHandler(); // key: jsonOutput pushKey("encrypt"); beginDict(bindJSON(&Handlers::beginEncrypt), bindBare(&Handlers::endEncrypt)); // .encrypt pushKey("userPassword"); @@ -262,9 +266,6 @@ popHandler(); // key: jsonStreamData pushKey("jsonStreamPrefix"); addParameter([this](std::string const& p) { c_main->jsonStreamPrefix(p); }); popHandler(); // key: jsonStreamPrefix -pushKey("toJson"); -addBare([this]() { c_main->toJson(); }); -popHandler(); // key: toJson pushKey("updateFromJson"); addParameter([this](std::string const& p) { c_main->updateFromJson(p); }); popHandler(); // key: updateFromJson diff --git a/libqpdf/qpdf/auto_job_schema.hh b/libqpdf/qpdf/auto_job_schema.hh index 0b9e29a9..0fc187fe 100644 --- a/libqpdf/qpdf/auto_job_schema.hh +++ b/libqpdf/qpdf/auto_job_schema.hh @@ -3,7 +3,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R"({ "password": "password for encrypted file", "passwordFile": "read password from a file", "empty": "use empty file as input", - "createFromJson": "create PDF from qpdf JSON", + "jsonInput": "input file is qpdf JSON", "outputFile": "output filename", "replaceInput": "overwrite input with output", "qdf": "enable viewing PDF code in a text editor", @@ -28,6 +28,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R"({ "forceVersion": "set output PDF version", "progress": "show progress when writing", "splitPages": "write pages to separate files", + "jsonOutput": "serialize to JSON", "encrypt": { "userPassword": "user password", "ownerPassword": "owner password", @@ -87,7 +88,6 @@ static constexpr char const* JOB_SCHEMA_DATA = R"({ ], "jsonStreamData": "how to handle streams in json output", "jsonStreamPrefix": "prefix for json stream data files", - "toJson": "serialize to JSON", "updateFromJson": "update a PDF from qpdf JSON", "allowWeakCrypto": "allow insecure cryptographic algorithms", "keepFilesOpen": "manage keeping multiple files open", |