tags:

views:

98

answers:

1
+2  Q: 

screenshot in php

I am using google visualization api for my php-based website. I am planning to use tcpdf to give a pdf version of the same images that i am generating using Google Visualization API.

is there any way to save these visualizations on my server so that i use them directly in the tcpdf?

If not then can i automatically take screenshots of the images and use them in tcpdf?

The reason why i am not manually taking screenshots and saving is that, all the values in the visualizations are dynamic and keep changing every day, so I am working on something automatic. Suggestions please?

+1  A: 

The result of the Google Visualization API can be an image or Flash (on interactive charts). If your result is an image (the most common) you can download it from the server to a server folder and add to the tcpdf from your local path.

you can use for example cURL:

$ch = curl_init($remoteURL);  // get the image from this url
$fp = fopen($localFile, "wb"); //put the image in this server path

// set URL and other appropriate options
$options = array(CURLOPT_FILE => $fp,
    CURLOPT_HEADER => 0,
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)
curl_setopt_array($ch, $options);

// Execute curl
curl_exec($ch);
curl_close($ch);

// close the file
fclose($fp);

Once the image is in a temporal path of your server you can add the image to the ctpdf using the "Image" method and the path to the file you have saved into your server.

  • The Server path must be writtable with the web server.This is specially important on *nix environments.

Here more ways to do the file download http://www.php-mysql-tutorial.com/wikis/php-tutorial/reading-a-remote-file-using-php.aspx

Dubas
But google visualization api has images in the form of javascript and not png or jpg... google chart api has it in png or jpg format.
Scorpion King
Image charts and Interactive charts are both part of the same API (Google Chart Tools) If you require to get the image into the Server to make the PDF you need to use the image version. SWF/Javascript versions are rendered on the client side.
Dubas