Subject: | PDF::Reuse "Didn't find pages" problem related to bug # 103758 |
Date: | Thu, 16 Apr 2015 09:38:46 +0000 |
To: | "bug-PDF-Reuse [...] rt.cpan.org" <bug-PDF-Reuse [...] rt.cpan.org> |
From: | "David Wong (davwong3)" <davwong3 [...] cisco.com> |
Sorry for creating another bug ID as I do not seem to be able to append to #103758 without an account.
My problem occurs in PDF::Reuse version 0.36.
I have created the following to demonstrate the problem. A third way down the code, you can comment out the first $tablepdf = create_table-pdf(...) and uncomment the second $tablepdf then it will work for all the iterations.
#!/usr/bin/perl
###############################################################################
# Create a new document temp_output.pdf
# Use page 1 of example.pdf as template input to create temp_table1.pdf with a table embedded
# Copy temp_table1.pdf into temp_output.pdf and close
# Create a new document output.pdf (got only 1 page)
# Copy a page from temp_output.pdf and add page number, footer
# Finally add bookmark and close output.pdf (got only 1 page)
###############################################################################
use strict;
use warnings;
use PDF::Reuse;
use PDF::Table;
use PDF::API2;
my $bookmark_heading = 'Tesing PDF::Reuse';
my $Footer_1 = "Copyright 2015";
my $Footer_2 = "Highly Confidential - Controlled Access";
my $Footer_3 = "A printed copy of this document is considered uncontrolled. Refer to the online version for the controlled revision.";
###############################################################################
# Set up files
###############################################################################
my $temp_outpdf = '.\temp_output.pdf';
my $temp_tablepdf = '.\temp_table';
my $template = '.\example.pdf';
my $outpdf = '.\output.pdf';
###############################################################################
# Create temporary output PDF
###############################################################################
my $tablepdf ;
#
for (1..10) {
prFile($temp_outpdf);
prCompress(1);
prFont('Times-Roman');
prFontSize(11);
$tablepdf = create_table_pdf($template,1,$temp_tablepdf);# this one fails and gives "Didn't find pages" error after
# random number of iterations. First one always good!
#my $tablepdf = $temp_tablepdf.'1'.'.pdf'; # this one works for all iterations
prDoc($tablepdf);
prEnd($temp_outpdf);
###############################################################################
# Add page number, footer and create bookmark
###############################################################################
my @pageMarks;
my $m = 1 ;
# new file
prFile($outpdf);
prFontSize(8);
while (1) {
# create bookmark
my $page = $m+1;
my $bookMark = {text => "Page $page",
act => "$m, 40,800"};
push @pageMarks, $bookMark;
# Create Footer
prText(72,56,"$Footer_1");
prText(391,56,"$Footer_2");
prText(125,42,"$Footer_3");
# Create page number
prText(303,56,$m++);
last unless prSinglePage($temp_outpdf);
}
prBookmark( { text => $bookmark_heading,
close => 1,
kids => \@pageMarks });
prEnd($outpdf);
print "Done \n";
}
###############################################################################
# Create a PDF file containing a table
###############################################################################
sub create_table_pdf {
my $template_file = shift;
my $page_number = shift;
my $temp_tablepdf = shift;
my $pdf = PDF::API2->new();
my $old = PDF::API2->open($template_file);
# Add a page from the template PDF as page 1 of the new PDF
my $page = $pdf->import_page($old, $page_number);
# create a table
my $pdftable = new PDF::Table;
my $hdr_props =
{
font => $pdf->corefont("Times", -encoding => "utf8"),
font_size => 13,
font_color => '#006666',
bg_color => 'light gray',
repeat => 1, # 1/0 eq On/Off if the header row should be repeated to every new page
};
my @csv_data = ([1,2,3],[2,3,4,],[3,4,5]);
# build the table layout
my $left_edge_of_table = 30;
$pdftable->table(
$pdf,
$page,
\@csv_data,
x => $left_edge_of_table,
w => 560,#540,
start_y => 600, # first page
next_y => 720, # subsequent pages
start_h => 570, # table height for first page
next_h => 640, # table height for subsequent pages
# some optional params
padding => 0,
# padding_right => 2,
background_color_odd => shift @_ || "#FFFFCC",
background_color_even => shift @_ || "#FFFFFF", #cell background color for even rows
header_props => $hdr_props, # see section HEADER ROW PROPERTIES
#column_props => $col_props,
);
my $tablepdf = $temp_tablepdf.'1'.'.pdf';
$old->end($template_file);
$pdf->saveas($tablepdf);
return($tablepdf);
}
Message body is not shown because it is too large.