SPUG:How to bundle images in PDF?

Jeff Almeida spud at spudzeppelin.com
Tue Jul 1 22:04:09 CDT 2003


Also Sprach SPUG-list-owner:
>My slightly altered version of your program (included below)
>works fine for viewing the PDFs it creates on Linux, using
>ghostview (gv 3.5.8) and Acrobat Reader 5.0.  However, I can't
>view the files it creates at all on my Windows 98 box, using Adobe
>Acrobat 5.0 (the latest and greatest), or Acrobat Reader 3
>(which is the entire collection of readers I've got there).
>When I try to open the files with Reader, I get "The file
>was damaged but is being repaired", followed by "there was an
>error opening this document.  Could not repair file."
>
>The Acrobat program itself gives a similar error, with a
>slightly different wording.
>
>I thought I'd try converting the PDFs to PS on Linux, and
>recreate them at PDF version 1.2 (using ps2pdf12) to see
>if that would make them readable (they're being created at
>level 1.4 now), but even pdf2ps complains about these files:
>
>Error: /ioerror in --.outpage-- <bunch of stack trace junk>
>Unrecoverable error, exit code 1.
>
>I don't see any indication of how to tweak the document
>properties in the PDF::API2 man page, and am wondering if the
>problem is just that it creates slightly malformed 1.4 output,
>but perhaps the output at lower levels would be correct.
>
>You can download one of my PDFs for testing at
>teachmeperl.com/YAPC.03/Shell::POSIX::Select/select_mono.pdf
>
>Any ideas?  Here's the script

The funky cross-platform behavior causes improper termination (maybe it 
really really wants \r\n or something like that) to leap to mind, but I've 
never had that problem with any of the PDF::API2 stuff I've done before.  
I have other ideas I've annotated below.

>#! /usr/bin/perl -w
>
>use PDF::API2;
>my $pdf = PDF::API2->new(-fit=>1);
>
>( $img_x, $img_y ) = ( 717, 538 );
>( $x, $y ) = ( $img_x + 72, $img_y + 18);
>
>$pdf->mediabox($x,$y) ;

That's kinda a nonstandard size for a global mediabox, and might cause 
problems with some viewers..?

>my ($img,$llx,$lly,$urx,$ury) = qw( 36 36  ) ;

This line makes me cringe, especially when combined with the results 
below...

>foreach (@ARGV) {
>	my ($img) = $pdf->image_jpeg($_);
>	my ($page) = $pdf->page();
>	my ($gfx) = $page->gfx();

Good so far, instantiating an image, a page, and a graphics context for 
putting the image on the page...

>	$gfx->image($img,$llx,$lly,$urx,$ury);

Right now, though, the above call is trying to set the geometry for the 
image on the page with three of the four coordinates undefined.  What you 
probably wanted was a combination of

my ($llx,$lly) = qw (36 36); #above, replacing the controversial line early

and $gfx->image($img,$llx,$lly); #in place of your existing call

Which will put the image a half-inch up and in from the lower right hand 
corner of the global mediabox (which the way you've set it, will actually 
cause the image to spill an eighth of an inch off the top) and not attempt 
to force the image size to conform.

>}
>my ($output) = $pdf->stringify();
>print "$output";


-- 

************************************************************
Jeff D. "Spud (Zeppelin)" Almeida
Little Elm, TX
spud at spudzeppelin.com



More information about the spug-list mailing list