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

Hi, I have a problem with PDF::Report.

I can generate the PDF without problems, but when I add a barcode, I can not open the file because it says the file is corrupt. When only text and lines, is generated correctly, but when I insert the barcode the file does not open

I think it's a problem with the parameters sent to the function.

Then leave the code snippet I am using.

my $pdf = new PDF::Report(PageSize => "A4", PageOrientation => "Portra +it"); $pdf->newpage( 0 ); $pdf->openpage( 0 ); $pdf->setSize( 8 ); $pdf->addRawText("Hola Mundo",300, 300); my $code = '31570918'; $pdf->drawBarcode(300, 500, 1, 1, '3of9', '31570918', '012345', 9+$zon +e, 9+$zone, 3+$zone, 0, '-', 0.5, 9, ''); print "Content-Disposition: attachment; filename=\"carnet.pdf\"\n\n"; print "Content-type: application/pdf\n\n"; print $pdf->Finish();

Worth mentioning is a web system, from which I generate patron cards.

Replies are listed 'Best First'.
Re: PDF::Report and barcode generation
by Corion (Patriarch) on Mar 18, 2015 at 15:23 UTC

    Did you binmode STDOUT properly? Ideally, before you print anything you run:

    binmode STDOUT;

    Also, HTTP headers are supposed to be delimited by \r\n, not a plain \n.

      Tested... and still the same problem :(

      As I said, without adding the barcode, is generated successfully

        I don't see use strict; or use warnings; -- are you using them? If so (or, if not, do so and then tell us, verbatim about and warnings, errors or relevant system log data that might apply.

Re: PDF::Report and barcode generation
by FreeBeerReekingMonk (Deacon) on Mar 19, 2015 at 21:00 UTC

    How about just testing the pdf as a standalone file too?

    open(FF, ">","/tmp/holamundo.pdf"); print FF $pdf->Finish(); close(FF);
    and view that pdf view a viewer, or drag and dropping into your browser?

    I created a small testcase (using miniserver.pl), and your pdf is displayed inline in the browser, with barcode and all, no problems. (at first I thought you needed extra mime encoding). It maybe the browser?

    print $client "HTTP/1.0 200 OK", Socket::CRLF; print $client "Content-type: application/pdf", Socket::CRLF; #view pdf + inline #print $client "Content-type: application/x-unknown", Socket::CRLF; # +force a save popup print $client Socket::CRLF; my $SLURP = `$localfile`; print $client $SLURP;

Re: PDF::Report and barcode generation
by hectorejch (Initiate) on Mar 20, 2015 at 14:41 UTC

    I tried with other readers, and opening the pdf with the same browser, and the file opens correctly.

    I conclude that the problem is the Acrobat Reader, which is very picky about some things, haha.

    You can give closed and resolved the issue. Thank you very much for your time and support.