i have the following code

<?php
   require_once 'includes/initialize.php';
    set_include_path( get_include_path() . PATH_SEPARATOR . CHARTS_PATH);

    require_once "class/pDraw.class.php";
    require_once "class/pImage.class.php";
    require_once "class/pData.class.php";

    // create data set
    $myDataset = array(0, 1, 1, 2, 3, 5, 8, 13);
    $myData = new pData();
    $myData->addPoints( $myDataset );
    $myData->setAxisName( 0, "Numbers" );

    // define image object
    $myImage = new pImage( 600, 300, $myData );
    $myImage->setFontProperties( array( "FontName" => CHARTS_PATH . "/fonts/GeosansLight.ttf", "FontSize" => 15 ) );
    $myImage->setGraphArea( 25,25, 475,275 );
    $myImage->drawScale();
    // output bar chart
    $myImage->drawBarChart();
    header( "Content-Type: image/png" );
    $myImage->Render( null );
?>

how can i modify the code so that it produces pdf document instead of image files

Recommended Answers

All 3 Replies

Use one of the PDF libraries out there. I use tcpdf and am very happy with it. Find a function in your pdf library that deals with images. In tcpdf it is the Image() function (see an example here). You can either save the generated image to disk and use it in the Image() function or send the Image() function a base64 encoded string representing the image.

commented: Thanks.. I am following same idea but i am strugling to save the image can you explain how to save the image and how to get the saved image url +0

Thanks.. I am following same idea but i am strugling to save the image can you explain how to save the image and how to get the saved image url

Thanks.. I am following same idea but i am strugling to save the image can you explain how to save the image and how to get the saved image url

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.