SPUG:How to bundle images in PDF?

SPUG-list-owner tim at consultix-inc.com
Tue Jul 1 12:38:44 CDT 2003


On Mon, Jun 30, 2003 at 08:59:38AM -0500, Jeff Almeida wrote:
> Tim was talking about this solution I sent him Saturday
> morning, but I don't think I actually sent it to the list, so
> here goes:

Jeff,

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

#! /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) ;

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

foreach (@ARGV) {
	my ($img) = $pdf->image_jpeg($_);
	my ($page) = $pdf->page();
	my ($gfx) = $page->gfx();
	$gfx->image($img,$llx,$lly,$urx,$ury);
}
my ($output) = $pdf->stringify();
print "$output";

-Tim
*------------------------------------------------------------*
| Tim Maher (206) 781-UNIX  (866) DOC-PERL  (866) DOC-UNIX   |
| CEO, JAWCAR ("Just Another White Camel Award Recipient")   |
| tim(AT)Consultix-Inc.Com  TeachMeUnix.Com  TeachMePerl.Com |
*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
|  Watch for my Book: "Minimal Perl for Shell Programmers"   |
*------------------------------------------------------------*



More information about the spug-list mailing list