Hi:

I am trying to create a PDF document using API2. I need to include a png image that I create using GD::Graphs. When I try to read in the the image I get the following error:

substr outside of string at /usr/lib/perl5/site_perl/5.8.3/PDF/API2/PDF/ImagePNG.pm line 137.

I am running on RedHat 9. I am using Perl v5.8.3, GD v1.53, and API2 v0.3r77...these should all be the latest available revisions from CPAN. The png file I create can be read in through various Linux and Windoz utilities, so I am fairly sure the file is for the most part valid.

If anyone has experienced this problem, I would appreciate any advice you might have. Also, if anyone has any links to good tutorials on GD, GD::Graph, and/or API2, this will help me out a lot. It is not always easy to see how all the pieces fit together by looking at the pod.

TIA,

John

P.S. -- below is a stripped down version of what I am trying to accomplish...thanks!

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#!/usr/bin/perl -w use strict; use GD::Graph::bars; use PDF::API2; createGraph(); createPdf(); exit; sub createGraph { my @xLabels = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); + my @data2002 = qw( 17 19 26 38 56 64 67 53 40 29 21 13 ); my @data2003 = qw( 19 24 27 41 56 69 75 60 44 33 22 15 ); my @data = ( \@xLabels, \@data2002, \@data2003 ); my $graph = GD::Graph::bars->new( 800, 600 ); $graph->set( title => "Rainfall 2002/2003", y_label => "Millimetres" + ); my $image = $graph->plot( \@data ) or die( "Cannot create image" ); open OUT, ">demo.png"; binmode OUT; print OUT $image->png(); close OUT; } sub createPdf { my $hPdf = PDF::API2->new(-file => "demo.pdf"); my $hPage = $hPdf->page(); my $hGfx = $hPage->gfx(); $hPage->mediabox(300, 300); my $hImg = $hPdf->image('demo.png'); $hGfx->image($hImg, 0, 0); print $hPdf->stringify(); $hPdf->end; }
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

20040510 Edit by Corion: Changed formatting of code to use CODE tags
Edit by castaway, added readmore tags


In reply to Problem using PNG images created by GD::Graphs in an API2 PDF doc by jmo0099

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.