JpGraph and PDF

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iulian.ilea

    #1

    JpGraph and PDF

    Hi,

    I use JpGraph to generate some graphs and I have to include those
    graphs in a pdf file, generated usign fPDF (http://www.fpdf.org/). If I
    include a png file it's ok, the pdf file is generated, everithing goes
    ok. If I use this code:
    ___
    $logo=file_get_ contents('splin eex1.php');
    //Output it (requires PHP>=4.3.2 and FPDF>=1.52)
    $pdf->Image('var://logo', 0, 0, 150, 0, 'PNG');
    ___

    ....to include genereted graph i get this error:
    ___
    CGI Error
    The specified CGI application misbehaved by not returning a complete
    set of HTTP headers. The headers it did return are:
    ___

    So, I need to save generated graph into a file and then to include in
    pdf using
    ___
    $logo=file_get_ contents('splin eex1.png');
    //Output it (requires PHP>=4.3.2 and FPDF>=1.52)
    $pdf->Image('var://logo', 0, 0, 150, 0, 'PNG');
    ___

    The problem is that I can't find how to save it.




    I use PHP 4.....

  • iulian.ilea

    #2
    Re: JpGraph and PDF


    iulian.ilea wrote:
    Hi,
    >
    I use JpGraph to generate some graphs and I have to include those
    graphs in a pdf file, generated usign fPDF (http://www.fpdf.org/). If I
    include a png file it's ok, the pdf file is generated, everithing goes
    ok. If I use this code:
    ___
    $logo=file_get_ contents('splin eex1.php');
    //Output it (requires PHP>=4.3.2 and FPDF>=1.52)
    $pdf->Image('var://logo', 0, 0, 150, 0, 'PNG');
    ___
    >
    ...to include genereted graph i get this error:
    ___
    CGI Error
    The specified CGI application misbehaved by not returning a complete
    set of HTTP headers. The headers it did return are:
    ___
    >
    So, I need to save generated graph into a file and then to include in
    pdf using
    ___
    $logo=file_get_ contents('splin eex1.png');
    //Output it (requires PHP>=4.3.2 and FPDF>=1.52)
    $pdf->Image('var://logo', 0, 0, 150, 0, 'PNG');
    ___
    >
    The problem is that I can't find how to save it.
    >


    >
    I use PHP 4.....
    I made it work using a trick, but I hope I'll find another solution. If
    you have any ideaa... post it.

    trick:
    I use IIS. I created one virtual directory with a name... example (in
    my cased). After, I renamed the php script in scriptphp.png (i changed
    the extension to png) and from Virtual Directory tab in Internet
    Information Server, click Configuration, add new extension - png - and
    set it to be executed by php.

    Now, if I use:
    ___
    $pdf->Image("http://localhost/examples/scriptphp.png", 0, 0, 150, 0,
    'PNG');
    ___

    ....it works.

    I tried with curl too, but is not working. Or I can't make it work.

    Comment

    • NC

      #3
      Re: JpGraph and PDF

      iulian.ilea wrote:
      >
      I use JpGraph to generate some graphs and I have to include those
      graphs in a pdf file, generated usign fPDF (http://www.fpdf.org/). If I
      include a png file it's ok, the pdf file is generated, everithing goes
      ok. If I use this code:
      ___
      $logo=file_get_ contents('splin eex1.php');
      If you do this, $logo will contain your PHP code. To get the image,
      you need to do:

      $logo = file_get_conten ts('http://localhost/path/splineex1.php') ;
      So, I need to save generated graph into a file
      You could, but you don't have to (see above). If you still want to
      save the image into a file, you can do it inside splineex1.php by
      specifying the target file name as a second argument to imagepng().
      See imagepng() dicumentation:

      Output a PNG image to either the browser or a file


      Alternatively, you could do:

      $logo = file_get_conten ts('http://localhost/path/splineex1.php') ;
      $fp = fopen('splineex 1.png', 'w');
      fwrite($fp, $logo);
      fclose($fp);

      Cheers,
      NC

      Comment

      Working...