Commit caab1b0e1642bc6ee0194c7ab4c4a4de2ab22f2c

Authored by Jay Berkenbilt
1 parent 4071db59

Handle pages with no /Contents from getPageContents()

The spec allows /Contents to be omitted for pages that are blank, but
QPDFObjectHandle::getPageContents() was throwing an exception in this
case.
ChangeLog
  1 +2014-11-14 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * Bug fix: QPDFObjectHandle::getPageContents() no longer throws an
  4 + exception when called on a page that has no /Contents key in its
  5 + dictionary. This is allowed by the spec, and some software
  6 + packages generate files like this for pages that are blank in the
  7 + original.
  8 +
1 9 2014-06-07 Jay Berkenbilt <ejb@ql.org>
2 10  
3 11 * 5.1.2: release
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -633,7 +633,7 @@ QPDFObjectHandle::getPageContents()
633 633 {
634 634 result.push_back(contents);
635 635 }
636   - else
  636 + else if (! contents.isNull())
637 637 {
638 638 throw std::runtime_error("unknown object type inspecting /Contents "
639 639 "key in page dictionary");
... ...
qpdf/qtest/qpdf.test
... ... @@ -199,7 +199,7 @@ $td-&gt;runtest(&quot;remove page we don&#39;t have&quot;,
199 199 show_ntests();
200 200 # ----------
201 201 $td->notify("--- Miscellaneous Tests ---");
202   -$n_tests += 72;
  202 +$n_tests += 73;
203 203  
204 204 $td->runtest("qpdf version",
205 205 {$td->COMMAND => "qpdf --version"},
... ... @@ -554,6 +554,11 @@ $td-&gt;runtest(&quot;check file&quot;,
554 554 {$td->FILE => "a.pdf"},
555 555 {$td->FILE => "indirect-decode-parms-out.pdf"});
556 556  
  557 +$td->runtest("handle page no with contents",
  558 + {$td->COMMAND => "qpdf --show-pages page-no-content.pdf"},
  559 + {$td->FILE => "page-no-content.out", $td->EXIT_STATUS => 0},
  560 + $td->NORMALIZE_NEWLINES);
  561 +
557 562 show_ntests();
558 563 # ----------
559 564 $td->notify("--- Numeric range parsing tests ---");
... ...
qpdf/qtest/qpdf/page-no-content.out 0 → 100644
  1 +page 1: 3 0 R
  2 + content:
  3 + 6 0 R
  4 +page 2: 4 0 R
  5 + content:
  6 +page 3: 5 0 R
  7 + content:
  8 + 9 0 R
... ...
qpdf/qtest/qpdf/page-no-content.pdf 0 → 100644
No preview for this file type