Subject: | Saving (modifying) PDF with only one xref table produces corrupt file. |
Suppose we have PDF with only one xref table -- i.e. file is not
linearised and was not incrementally saved before. Examaple is attached.
Suppose we run simple program on attached in.pdf:
use warnings;
use strict;
use CAM::PDF;
my $doc = CAM::PDF->new('in.pdf');
my $p = $doc->getPageContent(1);
$doc->setPageContent(1, $p);
$doc->output('out.pdf');
Actually, in this example we just modify one object. Modified PDF
(out.pdf) is corrupt.
xref table, added by CAM-PDF, is as follows:
xref
0 12
0000000000 65535 f
0000000002 00001 f
0000000003 00001 f
0000000004 00001 f
0000000006 00001 f
0000002796 00001 n
0000000007 00001 f
0000000008 00001 f
0000000009 00001 f
0000000010 00001 f
0000000011 00001 f
0000000000 00001 f
ALL objects (not one) are included and all are marked as free! That is
certainly wrong.
As a quick and dirty fix, which works for me, one line in procedure save
can be changed from:
if (!$self->{trailer}->{Prev})
to:
if (!$self->{startxref})
Though it requires more thought and testing. Also, fix from my
big-report 76513 should be applied to save modified file as expected.
Best regards,
Vadim
Subject: | in.pdf |
Message body not shown because it is not plain text.
Subject: | out.pdf |
Message body not shown because it is not plain text.