sivaramanm has asked for the wisdom of the Perl Monks concerning the following question:

hello monks

I want to convert pdf files to jpeg files

I tried as follows

use PDF::API2; # $pdf = PDF::API2->new; $pdf = PDF::API2->open('c:\temp.pdf'); $page = $pdf->page; $page = $pdf->openpage($pagenum); $file = 'c:\/siva.jpeg'; $img = $pdf->image_jpeg('siva.jpeg');

But I got an error as can't call method a"val" on an undefined value at C:\perl\site\lib\PDF\API2\Resource\XObject\Image.pm line 99

pls help me

Thanks

Siva

2006-08-07 Retitled by planetscape, as per Monastery guidelines: one-word (or module-only) titles hinder site navigation

( keep:0 edit:17 reap:0 )

Original title: 'pdf2jpeg'

  • Comment on 'can't call method a"val" on an undefined value' error with PDF::API2
  • Download Code

Replies are listed 'Best First'.
Re: 'can't call method a"val" on an undefined value' error with PDF::API2
by andyford (Curate) on Aug 07, 2006 at 16:28 UTC
    What happens when $pagenum is set to some number?
Re: 'can't call method a"val" on an undefined value' error with PDF::API2
by lorn (Monk) on Aug 07, 2006 at 19:11 UTC
Re: 'can't call method a"val" on an undefined value' error with PDF::API2
by McDarren (Abbot) on Aug 08, 2006 at 02:41 UTC
    Hello sivaramanm,

    I think you are a bit confused here. Firstly, it appears to me that you have simply copied/pasted the code example from the PDF::API2 synopsis, and expected it to somehow magically do what you want. That's not going to happen :)

    You have $pdf = PDF::API2->new;, immediately followed by $pdf = PDF::API2->open('c:\temp.pdf');. So which is it? Are you creating a new PDF object/file, or opening an existing one?

    You then do $page = $pdf->openpage($pagenum); - that is attempting to open a page at a non-defined page number (hence the error).

    Finally, you have $img = $pdf->image_jpeg('siva.jpeg');. Now I may be wrong here (as I've not used this module before), but from a quick read of the docs I get the understanding that the image_jpeg method will create an image object from an EXISTING jpeg file. Which is probably the opposite to what you were expecting.

    So it appears to me that PDF::API2 may not be able to do what you want, and you may instead need to look at ImageMagik's convert, as lorn suggested.