Preserve input PDF version on pages/split-pages (fixes #610)

This commit is contained in:
Jay Berkenbilt 2022-02-08 11:27:38 -05:00
parent cfd5147d92
commit f91b21c7d4
71 changed files with 63 additions and 30 deletions

View File

@ -1,11 +1,22 @@
2022-02-08 Jay Berkenbilt <ejb@ql.org>
* Bug fix: when splitting pages with --split-pages or selecting
pages with --pages, set the output PDF version to the maximum of
all the input PDF versions. This is a fix to QPDFJob. If you are
creating output PDF files yourself from multiple inputs, you will
need to code the same thing. The new PDFVersion object, its
updateIfGreater() method, and the new QPDF and QPDFWriter methods
described below make this very easy to do. Fixes #610.
* Add new class PDFVersion for more convenient comparison of PDF
version numbers from the %!PDF header.
* Add QPDF::getVersionAsPDFVersion() to return the PDF version and
extension together as a PDFVersion object instead of a string.
* Add a QPDFWriter::setMinimumPDFVersion() that takes a PDFVersion
object.
2022-02-06 Jay Berkenbilt <ejb@ql.org>
* Pl_Buffer and QPDFWriter: add getBufferSharedPointer(), which

5
TODO
View File

@ -1,8 +1,3 @@
10.6
====
* https://github.com/qpdf/qpdf/issues/610
Next
====

View File

@ -26,6 +26,7 @@
#include <qpdf/Constants.h>
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFPageObjectHelper.hh>
#include <qpdf/PDFVersion.hh>
#include <memory>
#include <string>
@ -587,6 +588,7 @@ class QPDFJob
int flatten_annotations_required;
int flatten_annotations_forbidden;
bool generate_appearances;
PDFVersion max_input_version;
std::string min_version;
std::string force_version;
bool show_npages;

View File

@ -42,11 +42,11 @@
#include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/QPDFObjGen.hh>
#include <qpdf/QPDFXRefEntry.hh>
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/PointerHolder.hh>
#include <qpdf/Pipeline.hh>
#include <qpdf/Buffer.hh>
#include <qpdf/PDFVersion.hh>
class QPDF;
class Pl_Count;
@ -265,6 +265,8 @@ class QPDFWriter
// streams are used.
QPDF_DLL
void setMinimumPDFVersion(std::string const&, int extension_level = 0);
QPDF_DLL
void setMinimumPDFVersion(PDFVersion const&);
// Force the PDF version of the output file to be a given version.
// Use of this function may create PDF files that will not work

View File

@ -2047,6 +2047,7 @@ QPDFJob::doProcessOnce(
{
fn(pdf.get(), password);
}
this->m->max_input_version.updateIfGreater(pdf->getVersionAsPDFVersion());
return pdf;
}
@ -3472,6 +3473,7 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w)
{
w.setObjectStreamMode(m->object_stream_mode);
}
w.setMinimumPDFVersion(this->m->max_input_version);
if (! m->min_version.empty())
{
std::string version;

View File

@ -296,6 +296,15 @@ QPDFWriter::setMinimumPDFVersion(std::string const& version,
}
}
void
QPDFWriter::setMinimumPDFVersion(PDFVersion const& v)
{
std::string version;
int extension_level;
v.getVersion(version, extension_level);
setMinimumPDFVersion(version, extension_level);
}
void
QPDFWriter::forcePDFVersion(std::string const& version,
int extension_level)

View File

@ -148,6 +148,14 @@ For a detailed list of changes, please see the file
embedded NUL characters. Thanks to M. Holger for the
contribution.
- New ``PDFVersion`` class for representing a PDF version number
with the ability to compare and order PDF versions. Methods
``QPDF::getVersionAsPDFVersion`` and a new version of
``QPDFWriter::setMinimumPDFVersion`` use it. This makes it
easier to create an output file whose PDF version is the maximum
of the versions across all the input files that contributed to
it.
- The ``JSON`` object in the qpdf library has been enhanced to
include a parser and the ability to get values out of the
``JSON`` object. Previously it was a write-only interface. Even
@ -181,6 +189,10 @@ For a detailed list of changes, please see the file
- Some characters were not correctly translated from PDF doc
encoding to Unicode.
- When splitting or combining pages, ensure that all output files
have a PDF version greater than or equal to the maximum version
of all the input files.
10.5.0: December 21, 2021
- Packaging changes

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.6
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%¿÷¢þ
1 0 obj
<< /AcroForm 2 0 R /Pages 3 0 R /Type /Catalog >>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
checking indirect-r-arg.pdf
WARNING: indirect-r-arg.pdf (object 1 0, offset 76): unknown token while reading object; treating as string
WARNING: indirect-r-arg.pdf (object 1 0, offset 62): expected dictionary key but found non-name object; inserting key /QPDFFake1
WARNING: indirect-r-arg.pdf (object 1 0, offset 62): expected dictionary key but found non-name object; inserting key /QPDFFake2
checking indirect-r-arg.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%¿÷¢þ
1 0 obj
<< /PageLabels << /Nums [ 0 << /St 1 >> 21 << /P () /St 1 >> 23 << /S /r /St 1 >> 28 << /P () /St 1 >> 30 << /S /r /St 6 >> 32 << /P () /St 1 >> 33 << /S /D /St 2 >> 36 << /S /D /St 6 >> 40 << /P () /St 1 >> 41 << /S /D /St 12 >> 43 << /S /D /St 16059 >> 44 << /S /r /St 50 >> 50 << /S /r /St 54 >> ] >> /Pages 2 0 R /Type /Catalog >>

View File

@ -1,7 +1,7 @@
checking obj0.pdf
WARNING: obj0.pdf: file is damaged
WARNING: obj0.pdf (object 1 0, offset 77): expected n n obj
WARNING: obj0.pdf: Attempting to reconstruct cross-reference table
checking obj0.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.6
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.6
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.6
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.6
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.6
%©В╒Ч
%QDF-1.0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0

View File

@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%©В╒Ч
%QDF-1.0