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

Dear Monks,

I am using API2 package (to generate PDF report) for the first time and trying to test it via simple Hello World Code. The moment I try to write something to the pdf file, I get errors from Content.pm. If i simply create new file and save it, it does create blank pdf file. I am working in Linux environment.If there is another way to generate pdf report, please let me know.

This is my code:
use PDF::API2; use PDF::API2::Util; my $pdf = PDF::API2->new(); my $font = $pdf->corefont('Times-Roman'); my $page = $pdf->page; $page->mediabox(595,842); my $gfx=$page->gfx; $gfx->textlabel(50,780,$font,20,"Hello World! (3)"); #my $headline_text = $page->text; #$headline_text->text("Hello World"); $pdf->saveas("/tmp/HelloWorld.pdf"); $pdf->end();
and got this error:
error: Undefined subroutine &Compress::Zlib::compress called at /usr/l +ib/perl5/site_perl/5.8.0/PDF/API2/Content.pm line 102. context: ... 98: delete($self->{" $k"}); 99: } 100: if($self->{-docompress}==1 && $self->{Filter}) 101: { 102: $self->{' stream'}=Compress::Zlib::compress($self->{' stream'}); 103: $self->{' nofilt'}=1; 104: delete $self->{-docompress}; 105: } 106: $self->SUPER::outobjdeep(@_); ... code stack: /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Content.pm:102 /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Basic/PDF/File.pm:953 /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Basic/PDF/File.pm:1255 /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Basic/PDF/File.pm:500 /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Basic/PDF/File.pm:436 /usr/lib/perl5/site_perl/5.8.0/PDF/API2.pm:893 /usr/local/apache/html/bioinfo/pfc/view/view_dige.mhtml:52 /usr/local/apache/html/bioinfo/pfc/view/autohandler:107 /usr/local/apache/html/bioinfo/pfc/view/syshandler:42

Replies are listed 'Best First'.
Re: Errors while generating PDF report
by runrig (Abbot) on Apr 21, 2008 at 16:39 UTC
    Did you install Compress-Zlib?? It's listed as a prerequisite for PDF-API2.

    Update: I wonder what versions of modules you have and/or how you installed the modules. PDF::API2::Content use's Compress::Zlib, so if Compress::Zlib wasn't installed, it should fail at the point of use. If it is installed, there should be a compress function available (you can look in the module yourself). Something strange is going on, so unless someone has some other helpful hint, you'll have to debug this yourself.

      Hi Monks,

      I installed Compress::Zlib before installing API2 package.
      Since API2 isn't working, i tried PDF::Create, PDF::Reuse packages as well, but all of them give some error from Content.pm.
      So I thought of generating Word document using Win32::Word::writer package (i cant generate text file cause my report will have images) but it won't install on linux machine.
      I am stuck. Please help.

Re: Errors while generating PDF report
by holli (Abbot) on Apr 21, 2008 at 16:58 UTC
Re: Errors while generating PDF report
by mscharrer (Hermit) on Apr 21, 2008 at 16:52 UTC
    You should install Compress::Zlib:
    shell# cpan cpan> install Compress::Zlib [...] cpan> quit
    and then it might still be necessary to manually load it with use Compress::Zlib;.
      I didn't used any of the PDF:: modules yet, only have some experience with the Apache FOP generator, but I would bet that they are not able to compete with LaTeX PDF output, as long they aren't using it as back-end. FOP can't, at least what I saw so far, maybe with better settings it gets better.

      I'm talking about document layout quality. Most tools only translate tags from one format to the other (e.g. HTML to PDF) which results e.g. in poor page breaks and ugly spacing.

      For longer documents I would generate LaTeX code from Perl and compile it with pdflatex. The drawback is that you have to know LaTeX for this. But this could be wrapped into a modules, maybe there is already one on CPAN.

Re: Errors while generating PDF report
by igelkott (Priest) on Apr 21, 2008 at 16:43 UTC
    error: Undefined subroutine &Compress::Zlib::compress

    Missing Compress::Zlib perhaps?

    Might want to check the FAQ as well.