Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Open page error for PDF::API2

by ikkon (Monk)
on Mar 06, 2007 at 21:16 UTC ( #603514=perlquestion: print w/ replies, xml ) Need Help??
ikkon has asked for the wisdom of the Perl Monks concerning the following question:

this was working last week, I made a few changes to some text in the perl but nothing that would stop it from working. on the line my $page = $pdf->openpage(1); the script will stop and give me a error
Can't call method "infilt" on an undefined value at /usr/lib/perl5/site_perl/5.8.5/PDF/API2/Util.pm line 667 (#1) (F) You used the syntax of a method call, but the slot filled by t +he object reference or package name contains an undefined value. Som +ething like this will reproduce the error: $BADREF = undef; process $BADREF 1,2,3; $BADREF->process(1,2,3); Uncaught exception from user code: Can't call method "infilt" on an undefined value at /usr/lib/p +erl5/site_perl/5.8.5/PDF/API2/Util.pm line 667. at /usr/lib/perl5/site_perl/5.8.5/PDF/API2/Util.pm line 667 PDF::API2::Util::unfilter('PDF::API2::Basic::PDF::Name=HASH(0x +96dc8a8)', 'H\x{89}\x{8c}V\x{c9}n\x{db}0\x{10}\x{bd}\x{eb}+\x{e6}\x{d +8}\x{1e}\x{c2}p\x{19}.\x{2}\x{c}\x{1}\x{b1}Q\x{17}H\x{da}K#\x{a0}\x{8 +7} (\x{8c}\x{d4}M\x{9d}\x{ca}\x{d}*\x{c7}\x{9}\x{d2}\x{af}\x{ef}p\x{9 +3}(;As\x{90}\x{c4}ef\x{de}\x{9b}\x{e1}\x{a3}\x{c8}?...') called at /u +sr/lib/perl5/site_perl/5.8.5/PDF/API2.pm line 991 PDF::API2::openpage('PDF::API2=HASH(0x93b0a10)', 1) called at +/opt/apache-tomcat-5.5.12/webapps/CalculatorPrinting/WEB-INF/cgi/HPSO +AReport.pl line 510
I can't figure out why its haulting at this point, I created a template in Adobe indesign and saved it as a PDF, in which i have API2 open it and add some content, again this all worked last week I checked the indesign for the compression and i have no compression on it at all, so I am not sure the problem is there or not. here is the are where it is failing ( the complete code is too large to put here, strict and warnings are used)
########################### MAKE PDF ############################ my $Template = 'HP_SOA_Assement.pdf'; my $pdf = PDF::API2->open($Template); my $page = $pdf->openpage(1); ##### Set Font ############### my %font = ( Helvetica => { Bold => $pdf->corefont('Helvetica-Bold', -encoding => +'utf-8'), Roman => $pdf->corefont('Helvetica', -encoding => +'utf-8'), Italic => $pdf->corefont('Helvetica-Oblique', -encoding => +'utf-8'), }, Futura => { Bold => $pdf->ttfont('FtraHv__.ttf', -encoding => 'utf +-8'), Medium => $pdf->ttfont('FtraMd__.ttf', -encoding => 'u +tf-8'), Lite => $pdf->ttfont('FtraLt__.ttf', -encoding => 'utf- +8'), }, ); ## Set Text ############### newText($fontType, 'Bold', 12/pt, 'black', 13/mm, 91/mm, $valueHash{" +forCover"}); newText($fontType, 'Bold', 10/pt, 'black', 13/mm, 81/mm, $valueHash{" +byCover"}); ######################################## PAGE 2 #################### +##################################### $page = $pdf->openpage(2); sub newText{ my $flashVars = $page->text; $flashVars->font( $font{$_[0]}{$_[1]}, $_[2] ); $flashVars->fillcolor( $_[3] ); $flashVars->translate( $_[4], $_[5] ); $flashVars->text( $_[6] ); }
Any Ideas as to why this is happening?

Comment on Open page error for PDF::API2
Select or Download Code
Re: Open page error for PDF::API2
by traveler (Parson) on Mar 06, 2007 at 23:22 UTC
    It looks as though one possibility is that an input filter is missing. Did you change machines, or was PDF::API2 updated? If not, it may be due to the template being created on Windows, the prog being run on *nix, and the need of the file to be converted (e.g. newlines). That conversion appears to be done by the filters. Does any of this ring a bell?

    --traveler

      ... and the need of the file to be converted (e.g. newlines).

      I think you meant to say

      ... and the need of the file not to be converted ... :)

      Always treat PDFs as binary files! Line endings conversions will surely ruin the file.

      Actually, this could be the problem here. Maybe ikkon uploaded the file to the webserver via FTP, and forgot to set binary mode? Just an idea. It's hard to tell what the real problem is without being able to take a look at the PDF file.

      That conversion appears to be done by the filters.

      Not quite (at least not if "that" refers to "newline"). The filters handle just the de/encoding of the stream part of the PDF objects1. Typically, filters are being used for compressing data, but there are other uses as well.

      In case your PDF file should turn out not to be broken otherwise, maybe it's making use of some fancy filter that PDF::API2 doesn't implement (yet). This might possibly lead to the method infilt being called on an undefined filter object eventually... (which is the error you're observing). Just guessing again.

      ___

      1  A little background: Roughly speaking, PDF files consist of a series of numbered objects. The numbers allow them to be referenced from within other objects. The objects themselves consist of a dictionary part (meta info), and an optional stream part (data). The latter may hold the drawing primitives that make up the text/graphics content of a page.   At the end of every PDF is an index table which lists the byte offsets of all objects in the file. This is mainly for performance / resource usage reasons, so some reader software can directly seek to the respective position where the required object is found, without having to parse the entire file (which makes sense when displaying just a single page from a document with hundreds of pages...). This direct indexing feature is one of the reasons why PDF files must be treated binary. As soon as you move around, or change the size of objects, the index table needs to be recomputed. This of course won't happen automagically when (size-modifying) Windows-to-Unix newline translations are being applied, for example... (though some readers will try to auto-fix a broken file).   Hope this helps :)

        I have tried all the suggestions, made sure in the FTP it was sending binary, Compress::Zlib is installed, I doubt it that its the actual perl file being the problem for I have only changed a few text, however i have recently changed the pdf, I still have yet been able to get it to work if you need to see the pdf file i can send it to you if that help, and also put the .pl file in my scratchpad (Its a bit ugly, was a fast hack). I am still trying thing to see what i can come up with
Re: Open page error for PDF::API2
by Khen1950fx (Canon) on Mar 07, 2007 at 00:32 UTC
    In addition to a missing input filter, there's a couple of other issues that you need to consider. You mentioned that inDesign didn't have compression. I don't know about that, but Compress::Zlib v1.0 is a prerequisite for PDF::API2. As for encoding, PDF::API2 uses Encode and utf8. utf8 is default; hence, you don't need to use  -encoding => 'utf8'. I tried it, and it spit it back at me. Also, I had some problems getting the fonts to work. You might want to check out the examples for truefonts and corefonts.
Re: Open page error for PDF::API2
by ikkon (Monk) on Mar 07, 2007 at 15:14 UTC
    from what I have been troubleshooting, i think i figured out that its not the pdf, its the script itself i used old code that was working with a old pdf that was working and it worked fine. but when i replaced the old script with my new script but kept the old pdf, it failed with the same error, so I have to assume its the script I tried deleting everything i edited in the script, but it still failed at the same point in the script, the old script is too out dated to use, other wise I would revert back. perhaps re-writting it might solve some problems
Re: Open page error for PDF::API2
by ikkon (Monk) on Mar 07, 2007 at 18:16 UTC
    I am still assumeing its not my script, other pdf scripts that where on the server that where working now have stopped working and giving the same error,

    The administrator (though no real help) gave me a list of updates that was recently updated , which i can assume that might be the problem. Though i do not know if this will be a problem or not (not the best with servers)

    would anyone by chance know if any of these updates would create a problem?

    here are the updates:

      Hi, I just took a look at the PDF file you sent me, and I'm pretty sure the file itself is absolutely OK. Also, it does not make use of any weird filters (it uses nothing but the standard "FlateDecode" (to uncompress zlib streams), and "DCTDecode" (for jpeg images)). And PDF::API2 can load it just fine for me.

      So, I suppose the problem is rather with loading some underlying library in your environment - presumably something to do with libz, as that's what's needed under the hood for the FlateDecode filter.   (BTW, in the CB log I saw that you mentioned getting Undefined subroutine &Compress::Zlib::compress ... - What exactly did you do to get that error? - it didn't show up in the original errors you posted.)

      Anyhow, with the following minimal program (and your PDF file)

      use PDF::API2; my $pdf = PDF::API2->open('HP_SOA_Assement.pdf'); my $page = $pdf->openpage(1);

      it would require the FlateDecode filter, and thus have to load libz and stuff... (and, if I understood you correctly, the openpage call is already failing).

      Running strace -o trace.out perl the-above-script.pl might help to narrow down on where exactly things are going wrong...   (probably easiest, if you send me the trace output).

        I fixed it finaly, not exactly sure what the problem way but it seems when perl was updated something got messed up, so I completely uninstalled perl and all the modules and reinstalled everything again, and it worked, so I am a happy camper, thanks for all the help

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://603514]
Approved by GrandFather
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-08-21 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (144 votes), past polls