Subject: | Fix for PDF generation causing error messages with paid Acrobat versions |
PDF::Table generates PDF which causes paid Adobe Acrobat sometimes to loudly claim that
the PDF file is broken even if it works with the free Acrobat Reader and other PDF viewers.
The changes needed to fix this are very small, just ordering PDF commands around a bit:
1) drawing line segments with no matching stroke operation at the end. Acrobat complains
about the next command happening within unfinished path construction.
FIX: Only draw the line segments if we're going to stroke later, not just always draw
everything and then stroke conditionally.
2) setting color after building drawing path before fill command. Acrobat claims this is a
syntax error.
FIX: First set color, then draw path rectangle/line segments, then stroke/fill.
These changes are pretty minor and should not break anything. See attached DIFF for out
solution. I tried to code using the existing style.
Background: We had trouble with PDF::Table generated output and users of paid Acrobat 7.
We used Acrobat Pro 9 (free 30 day trial ;-) to debug the issue, the PreFlight PDF Syntax
check showed the above issues quite clearly.
Info: PDF::Table 0.9.3, Perl 5.8.8, OSX and Linux.
Thanks for a great Perl module!
Subject: | PDF-Table-0.9.3-acrobat-syntax-error-fix.diff |
--- PDF-Table-0.9.3.original/lib/PDF/Table.pm 2006-12-27 16:44:26.000000000 +0200
+++ PDF-Table-0.9.3/lib/PDF/Table.pm 2008-11-05 16:45:40.000000000 +0200
@@ -462,9 +455,11 @@
# Draw the top line
$cur_y = $table_top_y;
+ # Only create path when we will stroke later -- avoid Acrobat 9.0.0 PreFlight Syntax errors
+ if($line_w) {
$gfx->move( $xbase , $cur_y );
$gfx->hline($xbase + $width );
-
+ }
# Each iteration adds a row to the current page until the page is full
# or there are no more rows to add
while(scalar(@{$data}) and $cur_y-$row_h > $bot_marg)
@@ -598,7 +593,7 @@
$col_props->[$j]->{'background_color'} ||
$background_color )
{
- $gfx_bg->rect( $cur_x, $cur_y-$row_h, $calc_column_widths->[$j], $row_h);
+ # Set color before drawing -- avoid Acrobat 9.0.0 PreFlight Syntax errors
if ( $cell_props->[$row_cnt][$j]->{'background_color'} && !$first_row )
{
$gfx_bg->fillcolor($cell_props->[$row_cnt][$j]->{'background_color'});
@@ -611,6 +606,7 @@
{
$gfx_bg->fillcolor($background_color);
}
+ $gfx_bg->rect( $cur_x, $cur_y-$row_h, $calc_column_widths->[$j], $row_h);
$gfx_bg->fill();
}
$cur_x += $calc_column_widths->[$j];
@@ -618,14 +614,21 @@
$cur_y -= $row_h;
$row_h = $min_row_h;
+ # Only create path when we will stroke later -- avoid Acrobat 9.0.0 PreFlight Syntax errors
+ if ($line_w) {
$gfx->move( $xbase , $cur_y );
$gfx->hline( $xbase + $width );
+ }
$rows_counter++;
$row_cnt++ unless ( $first_row );
$first_row = 0;
}# End of while(scalar(@{$data}) and $cur_y-$row_h > $bot_marg)
# Draw vertical lines
+
+ if($line_w) { # Only create path when we will stroke later -- avoid Acrobat 9.0.0 PreFlight Syntax errors
+ # Set color before lines -- avoid Acrobat 9.0.0 PreFlight Syntax errors
+ $gfx->fillcolor( $border_color);
$gfx->move( $xbase, $table_top_y);
$gfx->vline( $cur_y );
my $cur_x = $xbase;
@@ -637,8 +640,9 @@
}
# ACTUALLY draw all the lines
- $gfx->fillcolor( $border_color);
- $gfx->stroke if $line_w;
+ $gfx->stroke;
+ }# End of if($line_w)
+
$pg_cnt++;
}# End of while(scalar(@{$data}))
}# End of if(ref $data eq 'ARRAY')