Skip to content

Commit

Permalink
Preserve input PDF version on pages/split-pages (fixes qpdf#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkenbilt committed Feb 8, 2022
1 parent cfd5147 commit f91b21c
Show file tree
Hide file tree
Showing 71 changed files with 52 additions and 19 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
2022-02-08 Jay Berkenbilt <[email protected]>

* 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 <[email protected]>

* Pl_Buffer and QPDFWriter: add getBufferSharedPointer(), which
Expand Down
5 changes: 0 additions & 5 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
10.6
====

* https://github.com/qpdf/qpdf/issues/610

Next
====

Expand Down
2 changes: 2 additions & 0 deletions include/qpdf/QPDFJob.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <qpdf/Constants.h>
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFPageObjectHelper.hh>
#include <qpdf/PDFVersion.hh>

#include <memory>
#include <string>
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion include/qpdf/QPDFWriter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libqpdf/QPDFJob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,7 @@ QPDFJob::doProcessOnce(
{
fn(pdf.get(), password);
}
this->m->max_input_version.updateIfGreater(pdf->getVersionAsPDFVersion());
return pdf;
}

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions libqpdf/QPDFWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions manual/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Binary file modified qpdf/qtest/qpdf/01_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/02_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/03_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/04_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/05_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/06_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/07_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/08_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/09_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/10_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/11_split-exp.zdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/direct-dr-out.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/dr-with-indirect-item-out.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/fields-pages-out.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/fields-split-1.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/fields-split-2.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/indirect-r-arg.out
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified qpdf/qtest/qpdf/job-json-copy-attachments.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/job-json-empty-input.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/job-json-underlay-overlay-password.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/labels-split-01-06.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/labels-split-07-11.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/merge-implicit-ranges.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/merge-multiple-labels.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/merge-three-files-1.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/merge-three-files-2.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/obj0-check.out
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified qpdf/qtest/qpdf/overlay-copy-annotations-p1.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/overlay-copy-annotations-p2.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/overlay-copy-annotations-p5.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/overlay-copy-annotations-p6.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/overlay-copy-annotations.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/remove-labels.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-01.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-02.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-03.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-04.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-05.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-06.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-07.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-08.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-09.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-1
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-1.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-10.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-11.Pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-2
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-3
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-4
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-group-01-05.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-group-06-10.pdf
Binary file not shown.
Binary file modified qpdf/qtest/qpdf/split-exp-group-11-11.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_01
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_02
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_03
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_04
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_05
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_06
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_07
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_08
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_09
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_10
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
2 changes: 1 addition & 1 deletion qpdf/qtest/qpdf/split-exp.zdf_11
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%PDF-1.3
%PDF-1.4
%����
%QDF-1.0

Expand Down
Binary file modified qpdf/qtest/qpdf/uo-7.pdf
Binary file not shown.

0 comments on commit f91b21c

Please sign in to comment.