Reusing file names

75 views
Skip to first unread message

Jef

unread,
Jul 14, 2010, 9:32:29 AM7/14/10
to PDF-Reuse
Took me some time to figure out this bug :

With PDF::Reuse, you cannot re-use filenames, unless you use the trick
below.

My application work like this :
foreach my $repor (@reports) {
foreach my $page (@pages) {
prFile("page-".$cnt.".pdf);
### create page with PDF::Reuse
prEnd();
$cnt++;
}
prFile("report-".$report.".pdf);
for ($i=0; $i<$cnt; $i++) {
prDoc("page-".$i.".pdf");
}
prEnd();
for ($i=0; $i<$cnt; $i++) {
unlink("page-".$i.".pdf");
}
}

The problem is that as soon as I try to prDoc("page-0.pdf") for the
second time, I get "Didn't find pages " error message).

The cause is that PDF::Reuse is not re-entrant and (wrongly) assumes
that a file already processed will have the same content if re-
processed.

The solution I found is to add this piece of code after the unlinking
of all temporary PDF :
%PDF::Reuse::processed=();

Not elegant, but it works for now.

Two questions for Lars :
- is this the right thing to do ? (there may be some other variables
to re-initialize)
- can this be fixed in the code, or is this a design decision (in
order to avoid extra re-processing, I guess) ?

J-F

Reply all
Reply to author
Forward
0 new messages