Handle direct page objects (fixes #164)

This commit is contained in:
Jay Berkenbilt 2019-01-29 17:01:36 -05:00
parent 2d0885bc11
commit 8a9cfd2605
7 changed files with 144 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2019-01-29 Jay Berkenbilt <ejb@ql.org>
* Handle files with direct page objects, which is not allowed by
the PDF spec but has been seen in the wild. Fixes #164.
2019-01-28 Jay Berkenbilt <ejb@ql.org>
* Bug fix: when using --stream-data=compress, object streams and

View File

@ -105,7 +105,13 @@ QPDF::getAllPagesInternal3(QPDFObjectHandle cur_pages,
for (int i = 0; i < n; ++i)
{
QPDFObjectHandle kid = kids.getArrayItem(i);
if (seen.count(kid.getObjGen()))
if (! kid.isIndirect())
{
QTC::TC("qpdf", "QPDF handle direct page object");
kid = makeIndirectObject(kid);
kids.setArrayItem(i, kid);
}
else if (seen.count(kid.getObjGen()))
{
// Make a copy of the page. This does the same as
// shallowCopyPage in QPDFPageObjectHelper.

View File

@ -429,3 +429,4 @@ QPDFPageObjectHelper non-trivial inheritance 0
QPDFPageObjectHelper copy shared attribute 0
qpdf from_nr from repeat_nr 0
QPDF resolve duplicated page object 0
QPDF handle direct page object 0

View File

@ -2461,7 +2461,7 @@ for (my $n = 16; $n <= 19; ++$n)
show_ntests();
# ----------
$td->notify("--- Specific File Tests ---");
$n_tests += 4;
$n_tests += 7;
# Special PDF files that caused problems at some point
@ -2482,6 +2482,19 @@ $td->runtest("compress objstm and xref",
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "compress-objstm-xref.pdf"});
$td->runtest("direct pages",
{$td->COMMAND =>
"qpdf --static-id direct-pages.pdf --pages . -- a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "direct-pages-fixed.pdf"});
$td->runtest("show direct pages",
{$td->COMMAND =>
"qpdf --show-pages direct-pages.pdf"},
{$td->FILE => "direct-pages.out", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
show_ntests();
# ----------

Binary file not shown.

View File

@ -0,0 +1,6 @@
page 1: 7 0 R
content:
3 0 R
page 2: 8 0 R
content:
3 0 R

View File

@ -0,0 +1,111 @@
%PDF-1.3
%¿÷¢þ
%QDF-1.0
%% Original object ID: 1 0
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog
>>
endobj
%% Original object ID: 2 0
2 0 obj
<<
/Count 2
/Kids [
<<
/Contents 3 0 R
/MediaBox [
0
0
612
792
]
/Parent 2 0 R
/Resources <<
/Font <<
/F1 5 0 R
>>
/ProcSet 6 0 R
>>
/Type /Page
>>
<<
/Contents 3 0 R
/MediaBox [
0
0
612
792
]
/Parent 2 0 R
/Resources <<
/Font <<
/F1 5 0 R
>>
/ProcSet 6 0 R
>>
/Type /Page
>>
]
/Type /Pages
>>
endobj
%% Contents for page 2
%% Original object ID: 4 0
3 0 obj
<<
/Length 4 0 R
>>
stream
BT
/F1 24 Tf
72 720 Td
(Potato) Tj
ET
endstream
endobj
4 0 obj
44
endobj
%% Original object ID: 6 0
5 0 obj
<<
/BaseFont /Helvetica
/Encoding /WinAnsiEncoding
/Name /F1
/Subtype /Type1
/Type /Font
>>
endobj
%% Original object ID: 7 0
6 0 obj
[
/PDF
/Text
]
endobj
xref
0 7
0000000000 65535 f
0000000052 00000 n
0000000133 00000 n
0000000733 00000 n
0000000832 00000 n
0000000878 00000 n
0000001023 00000 n
trailer <<
/Root 1 0 R
/Size 7
/ID [<1323a5937c577a66735583a93698ce3c><372cbf44f6db88ab60d9263c0f0bd26a>]
>>
startxref
1058
%%EOF