diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh index 62992cd..45efafe 100644 --- a/include/qpdf/QPDFJob.hh +++ b/include/qpdf/QPDFJob.hh @@ -460,7 +460,6 @@ class QPDFJob bool main_input); // Transformations - void setQPDFOptions(QPDF& pdf); void handlePageSpecs(QPDF& pdf); bool shouldRemoveUnreferencedResources(QPDF& pdf); void handleRotations(QPDF& pdf); diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 4543fc9..41f701e 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -477,7 +477,7 @@ QPDFJob::writeQPDF(QPDF& pdf) if (!pdf.getWarnings().empty()) { m->warnings = true; } - if (m->warnings && (!m->suppress_warnings)) { + if (m->warnings && !m->qcf.suppress_warnings()) { if (createsOutput()) { *m->log->getWarn() << m->message_prefix @@ -635,24 +635,6 @@ QPDFJob::getEncryptionStatus() return m->encryption_status; } -void -QPDFJob::setQPDFOptions(QPDF& pdf) -{ - pdf.setLogger(m->log); - if (m->ignore_xref_streams) { - pdf.setIgnoreXRefStreams(true); - } - if (m->suppress_recovery) { - pdf.setAttemptRecovery(false); - } - if (m->password_is_hex_key) { - pdf.setPasswordIsHexKey(true); - } - if (m->suppress_warnings) { - pdf.setSuppressWarnings(true); - } -} - static std::string show_bool(bool v) { @@ -737,7 +719,6 @@ QPDFJob::doCheck(QPDF& pdf) bool okay = true; auto& cout = *m->log->getInfo(); cout << "checking " << m->infile_name() << "\n"; - pdf.doc().config().check_mode(true); try { int extension_level = pdf.getExtensionLevel(); cout << "PDF Version: " << pdf.getPDFVersion(); @@ -1728,7 +1709,7 @@ QPDFJob::doProcessOnce( bool main_input) { pdf = std::make_unique(); - setQPDFOptions(*pdf); + pdf->doc().config(m->qcf.log(m->log)); if (empty) { pdf->emptyPDF(); } else if (main_input && m->json_input) { @@ -1758,16 +1739,16 @@ QPDFJob::doProcess( // was incorrectly encoded, there's a good chance we'd succeed here. std::string ptemp; - if (password && (!m->password_is_hex_key)) { + if (password && !m->qcf.provided_password_is_hex_key()) { if (m->password_mode == QPDFJob::pm_hex_bytes) { // Special case: handle --password-mode=hex-bytes for input password as well as output // password - QTC::TC("qpdf", "QPDFJob input password hex-bytes"); ptemp = QUtil::hex_decode(password); password = ptemp.c_str(); } } - if ((password == nullptr) || empty || m->password_is_hex_key || m->suppress_password_recovery) { + if (!password || empty || m->qcf.provided_password_is_hex_key() || + m->suppress_password_recovery) { // There is no password, or we're not doing recovery, so just do the normal processing with // the supplied password. doProcessOnce(pdf, fn, password, empty, used_for_input, main_input); @@ -3034,12 +3015,10 @@ QPDFJob::doSplitPages(QPDF& pdf) last = num_pages; } QPDF outpdf; + outpdf.doc().config(m->qcf); outpdf.emptyPDF(); QPDFAcroFormDocumentHelper* out_afdh = afdh.hasAcroForm() ? &outpdf.doc().acroform() : nullptr; - if (m->suppress_warnings) { - outpdf.setSuppressWarnings(true); - } for (size_t pageno = first; pageno <= last; ++pageno) { QPDFObjectHandle page = pages.at(pageno - 1); outpdf.addPage(page, false); diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index 746b5be..667bac8 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -68,6 +68,7 @@ QPDFJob::Config* QPDFJob::Config::check() { o.m->check = true; + o.m->qcf.check_mode(true); o.m->require_outfile = false; return this; } @@ -233,7 +234,7 @@ QPDFJob::Config::generateAppearances() QPDFJob::Config* QPDFJob::Config::ignoreXrefStreams() { - o.m->ignore_xref_streams = true; + o.m->qcf.ignore_xref_streams(true); return this; } @@ -415,7 +416,7 @@ QPDFJob::Config::noOriginalObjectIds() QPDFJob::Config* QPDFJob::Config::noWarn() { - o.m->suppress_warnings = true; + o.m->qcf.suppress_warnings(true); return this; } @@ -465,7 +466,7 @@ QPDFJob::Config::password(std::string const& parameter) QPDFJob::Config* QPDFJob::Config::passwordIsHexKey() { - o.m->password_is_hex_key = true; + o.m->qcf.provided_password_is_hex_key(true); return this; } @@ -662,7 +663,7 @@ QPDFJob::Config::suppressPasswordRecovery() QPDFJob::Config* QPDFJob::Config::suppressRecovery() { - o.m->suppress_recovery = true; + o.m->qcf.attempt_recovery(false); return this; } diff --git a/libqpdf/qpdf/QPDFJob_private.hh b/libqpdf/qpdf/QPDFJob_private.hh index 5f80fd6..8fe9be0 100644 --- a/libqpdf/qpdf/QPDFJob_private.hh +++ b/libqpdf/qpdf/QPDFJob_private.hh @@ -5,6 +5,7 @@ #include #include +#include // A selection of pages from a single input PDF to be included in the output. This corresponds to a // single clause in the --pages option. @@ -149,7 +150,7 @@ class QPDFJob::Members public: Members(QPDFJob& job) : - log(QPDFLogger::defaultLogger()), + log(qcf.log()), inputs(job) { } @@ -167,6 +168,7 @@ class QPDFJob::Members static int constexpr DEFAULT_OI_MIN_AREA = 16384; static int constexpr DEFAULT_II_MIN_BYTES = 1024; + qpdf::Doc::Config qcf; std::shared_ptr log; std::string message_prefix{"qpdf"}; bool warnings{false}; @@ -179,11 +181,9 @@ class QPDFJob::Members int split_pages{0}; bool progress{false}; std::function progress_handler{nullptr}; - bool suppress_warnings{false}; bool warnings_exit_zero{false}; bool copy_encryption{false}; bool encrypt{false}; - bool password_is_hex_key{false}; bool suppress_password_recovery{false}; password_mode_e password_mode{pm_auto}; bool allow_insecure{false}; @@ -218,10 +218,8 @@ class QPDFJob::Members bool decode_level_set{false}; bool normalize_set{false}; bool normalize{false}; - bool suppress_recovery{false}; bool object_stream_set{false}; qpdf_object_stream_e object_stream_mode{qpdf_o_preserve}; - bool ignore_xref_streams{false}; bool qdf_mode{false}; bool preserve_unreferenced_objects{false}; remove_unref_e remove_unreferenced_page_resources{re_auto}; diff --git a/libqpdf/qpdf/QPDF_private.hh b/libqpdf/qpdf/QPDF_private.hh index 9e91505..98e0f81 100644 --- a/libqpdf/qpdf/QPDF_private.hh +++ b/libqpdf/qpdf/QPDF_private.hh @@ -504,6 +504,12 @@ class QPDF::Doc return cf; } + void + config(qpdf::Doc::Config val) + { + cf = val; + } + inline Linearization& linearization(); inline Objects& objects(); diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index dfbc25c..9d7fee2 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -248,7 +248,6 @@ QPDFJob password not encodable 0 QPDFJob auto-encode password 0 QPDFJob bytes fallback warning 0 QPDFJob invalid utf-8 in auto 0 -QPDFJob input password hex-bytes 0 QPDFFormFieldObjectHelper replaced BMC at EOF 0 QPDFFormFieldObjectHelper fallback Tf 0 QPDFPageObjectHelper copy shared attribute 1 diff --git a/qpdf/qtest/qpdf/catalgg.out b/qpdf/qtest/qpdf/catalgg.out index 58fb244..3c3b806 100644 --- a/qpdf/qtest/qpdf/catalgg.out +++ b/qpdf/qtest/qpdf/catalgg.out @@ -1,5 +1,5 @@ -checking catalgg.pdf WARNING: catalgg.pdf: catalog /Type entry missing or invalid +checking catalgg.pdf PDF Version: 1.3 File is not encrypted File is not linearized