aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-19 00:22:57 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-20 15:16:25 +0200
commit6f43bf8de36b08c55b172b4f4133c79657651666 (patch)
treeec17bbf42d9ea78d44ab3b9d2cac363cc6b9bc68 /include
parent23fc6756f1894e1af35853eb2251f08d5b25cf30 (diff)
downloadqpdf-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 'include')
-rw-r--r--include/qpdf/QPDF.hh45
-rw-r--r--include/qpdf/QPDFJob.hh33
-rw-r--r--include/qpdf/auto_job_c_main.hh5
3 files changed, 55 insertions, 28 deletions
diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh
index 146015dc..fc515898 100644
--- a/include/qpdf/QPDF.hh
+++ b/include/qpdf/QPDF.hh
@@ -111,23 +111,38 @@ class QPDF
processInputSource(std::shared_ptr<InputSource>, char const* password = 0);
// Create a PDF from an input source that contains JSON as written
- // by qpdf --json (version 2 or higher). The JSON must be a
- // complete representation of a PDF. See "QPDF JSON Format" in the
- // manual for details.
+ // by writeJSON (or qpdf --json-output, version 2 or higher). The
+ // JSON must be a complete representation of a PDF. See "QPDF JSON
+ // Format" in the manual for details.
QPDF_DLL
void createFromJSON(std::string const& json_file);
QPDF_DLL
void createFromJSON(std::shared_ptr<InputSource>);
// Update a PDF from an input source that contains JSON in the
- // same format as is written by qpdf --json (version 2 or higher).
- // Objects in the PDF and not in the JSON are not modified. See
- // "QPDF JSON Format" in the manual for details.
+ // same format as is written by writeJSON (or qpdf --json-output,
+ // version 2 or higher). Objects in the PDF and not in the JSON
+ // are not modified. See "QPDF JSON Format" in the manual for
+ // details.
QPDF_DLL
void updateFromJSON(std::string const& json_file);
QPDF_DLL
void updateFromJSON(std::shared_ptr<InputSource>);
+ // Write qpdf json format. The only supported version is 2. If
+ // wanted_objects is empty, write all objects. Otherwise, write
+ // only objects whose keys are in wanted_objects. Keys may be
+ // either "trailer" or of the form "obj:n n R". Invalid keys are
+ // ignored.
+ QPDF_DLL
+ void writeJSON(
+ int version,
+ Pipeline*,
+ qpdf_stream_decode_level_e,
+ qpdf_json_stream_data_e,
+ std::string const& file_prefix,
+ std::set<std::string> wanted_objects);
+
// Close or otherwise release the input source. Once this has been
// called, no other methods of qpdf can be called safely except
// for getWarnings and anyWarnings(). After this has been called,
@@ -1040,7 +1055,6 @@ class QPDF
bool parse_error;
bool saw_qpdf;
bool saw_objects;
- bool saw_json_version;
bool saw_pdf_version;
bool saw_trailer;
state_e state;
@@ -1571,6 +1585,23 @@ class QPDF
// JSON import
void importJSON(std::shared_ptr<InputSource>, bool must_be_complete);
+ // JSON write
+ void writeJSONStream(
+ int version,
+ Pipeline* p,
+ bool& first,
+ std::string const& key,
+ QPDFObjectHandle&,
+ qpdf_stream_decode_level_e,
+ qpdf_json_stream_data_e,
+ std::string const& file_prefix);
+ void writeJSONObject(
+ int version,
+ Pipeline* p,
+ bool& first,
+ std::string const& key,
+ QPDFObjectHandle&);
+
// Type conversion helper methods
template <typename T>
static qpdf_offset_t
diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh
index a7d86337..b0a3c560 100644
--- a/include/qpdf/QPDFJob.hh
+++ b/include/qpdf/QPDFJob.hh
@@ -323,8 +323,6 @@ class QPDFJob
Config* outputFile(std::string const& filename);
QPDF_DLL
Config* replaceInput();
- QPDF_DLL
- Config* createFromJson(std::string const& filename);
QPDF_DLL
std::shared_ptr<CopyAttConfig> copyAttachmentsFrom();
@@ -455,7 +453,10 @@ class QPDFJob
// Basic file processing
std::shared_ptr<QPDF> processFile(
- char const* filename, char const* password, bool used_for_input);
+ char const* filename,
+ char const* password,
+ bool used_for_input,
+ bool main_input);
std::shared_ptr<QPDF> processInputSource(
std::shared_ptr<InputSource> is,
char const* password,
@@ -464,12 +465,14 @@ class QPDFJob
std::function<void(QPDF*, char const*)> fn,
char const* password,
bool empty,
- bool used_for_input);
+ bool used_for_input,
+ bool main_input);
std::shared_ptr<QPDF> doProcessOnce(
std::function<void(QPDF*, char const*)> fn,
char const* password,
bool empty,
- bool used_for_input);
+ bool used_for_input,
+ bool main_input);
// Transformations
void setQPDFOptions(QPDF& pdf);
@@ -511,31 +514,21 @@ class QPDFJob
void setEncryptionOptions(QPDF&, QPDFWriter&);
void maybeFixWritePassword(int R, std::string& password);
void writeOutfile(QPDF& pdf);
+ void writeJSON(QPDF& pdf);
// JSON
void doJSON(QPDF& pdf, Pipeline*);
std::set<QPDFObjGen> getWantedJSONObjects();
+ void doJSONObject(
+ Pipeline* p, bool& first, std::string const& key, QPDFObjectHandle&);
void doJSONObjects(Pipeline* p, bool& first, QPDF& pdf);
void doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf);
- void doJSONQpdf(Pipeline* p, bool& first, QPDF& pdf);
void doJSONPages(Pipeline* p, bool& first, QPDF& pdf);
void doJSONPageLabels(Pipeline* p, bool& first, QPDF& pdf);
void doJSONOutlines(Pipeline* p, bool& first, QPDF& pdf);
void doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf);
void doJSONEncrypt(Pipeline* p, bool& first, QPDF& pdf);
void doJSONAttachments(Pipeline* p, bool& first, QPDF& pdf);
- void doJSONStream(
- Pipeline* p,
- bool& first,
- QPDF& pdf,
- QPDFObjectHandle& obj,
- std::string const& file_prefix);
- void doJSONObject(
- Pipeline* p,
- bool& first,
- QPDF& pdf,
- std::string const& key,
- QPDFObjectHandle& obj);
void addOutlinesToJson(
std::vector<QPDFOutlineObjectHelper> outlines,
JSON& j,
@@ -654,6 +647,7 @@ class QPDFJob
std::set<std::string> json_keys;
std::set<std::string> json_objects;
qpdf_json_stream_data_e json_stream_data;
+ bool json_stream_data_set;
std::string json_stream_prefix;
bool test_json_schema;
bool check;
@@ -676,7 +670,8 @@ class QPDFJob
bool check_requires_password;
std::shared_ptr<char> infilename;
std::shared_ptr<char> outfilename;
- std::string create_from_json;
+ bool json_input;
+ int json_output;
std::string update_from_json;
};
std::shared_ptr<Members> m;
diff --git a/include/qpdf/auto_job_c_main.hh b/include/qpdf/auto_job_c_main.hh
index cc1bf469..0b2b559d 100644
--- a/include/qpdf/auto_job_c_main.hh
+++ b/include/qpdf/auto_job_c_main.hh
@@ -17,6 +17,7 @@ QPDF_DLL Config* flattenRotation();
QPDF_DLL Config* generateAppearances();
QPDF_DLL Config* ignoreXrefStreams();
QPDF_DLL Config* isEncrypted();
+QPDF_DLL Config* jsonInput();
QPDF_DLL Config* keepInlineImages();
QPDF_DLL Config* linearize();
QPDF_DLL Config* listAttachments();
@@ -44,7 +45,6 @@ QPDF_DLL Config* staticId();
QPDF_DLL Config* suppressPasswordRecovery();
QPDF_DLL Config* suppressRecovery();
QPDF_DLL Config* testJsonSchema();
-QPDF_DLL Config* toJson();
QPDF_DLL Config* verbose();
QPDF_DLL Config* warningExit0();
QPDF_DLL Config* withImages();
@@ -77,12 +77,13 @@ QPDF_DLL Config* compressStreams(std::string const& parameter);
QPDF_DLL Config* decodeLevel(std::string const& parameter);
QPDF_DLL Config* flattenAnnotations(std::string const& parameter);
QPDF_DLL Config* jsonKey(std::string const& parameter);
+QPDF_DLL Config* jsonOutput(std::string const& parameter);
+QPDF_DLL Config* jsonStreamData(std::string const& parameter);
QPDF_DLL Config* keepFilesOpen(std::string const& parameter);
QPDF_DLL Config* normalizeContent(std::string const& parameter);
QPDF_DLL Config* objectStreams(std::string const& parameter);
QPDF_DLL Config* passwordMode(std::string const& parameter);
QPDF_DLL Config* removeUnreferencedResources(std::string const& parameter);
QPDF_DLL Config* streamData(std::string const& parameter);
-QPDF_DLL Config* jsonStreamData(std::string const& parameter);
QPDF_DLL Config* json(std::string const& parameter);
QPDF_DLL Config* json();