VeryPDF Web to PDF Converter Cloud API is a cloud service provided by VeryPDF. Developers can use the cloud API to enable the function of converting HTML webpage to PDF in their applications. The following words will tell you how to use the cloud API.
1. Registration | 2. Use API to convert HTML to PDF | ||
---|---|---|---|
3. Use API to Convert HTML to image | 4. Demonstration PHP code |
You need an account and an API key to use VeryPDF cloud service. You may follow the guide to register a VeryPDF cloud service account.
The following demonstration URL shows the basic options to convert HTML to PDF by VeryPDF Web to PDF Converter Cloud API.
http://online.verypdf.com/app/onlineapi/?apikey=XXXXXXXXX&inputfile=http://www.verypdf.com&type=htmltopdfsdk
In the URL, options are separated by character "&", and the basic options are:
API options for converting HTML to image are demonstrated in the following example URL.
http://online.verypdf.com/app/onlineapi/?apikey=XXXXXXXX&inputfile=http://www.verypdf.com&type=htmltoimagesdk&outputfiletype=jpg
In the URL, options "apikey" and "inputfile" are as same as those in conversion from HTML to PDF. To call the API to convert HTML to image, the option "type" should be assigned to "htmltoimagesdk", and the output image format is given by "outputfiletype=jpg". The API supports two image formats, PNG and JPG.
The following is a demonstration PHP code file to use VeryPDF Web to PDF Converter Cloud API. Please replace the "apikey" with your own key to test the API. (Register for an API key and get free points here)
Please click the link to see all options supported by VeryPDF Web to PDF Converter Cloud API, http://www.impdf.com/options.htm
<?php
function htmltopdfsdk()
{
$apikey = "XXXXXXXXXXXXXXXXXXXXXX";
$inputfile = "http://www.verypdf.com";
$url = "http://online.verypdf.com/app/onlineapi/";
$postfields = "apikey=" . $apikey ."&inputfile=". $inputfile . "&type=htmltopdfsdk&--title=HaHa123456HaHaHaHa";
$pdf = http_post($url, $postfields);
echo $pdf;
}
function htmltoimagesdk()
{
$apikey = "XXXXXXXXXXXXXXXXXXXXXX";
$inputfile = "http://www.verypdf.com";
$url = "http://online.verypdf.com/app/onlineapi/";
$postfields = "apikey=" . $apikey ."&inputfile=". $inputfile . "&type=htmltoimagesdk&outputfiletype=jpg";
$pdf = http_post($url, $postfields);
echo $pdf;
}
// htmltopdfsdk(); // uncomment this line to convert HTML to PDF
// htmltoimagesdk(); //uncomment this line to convert HTML to image
function http_post($url, $postfields)
{
if (!function_exists("curl_init"))
{
return "missing curl";
}
$c = curl_init();
curl_setopt($c, CURLOPT_URL,$url);
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($c, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
$http_code = 0;
$error = "";
$response = curl_exec($c);
$http_code = curl_getinfo($c, CURLINFO_HTTP_CODE);
$error_str = curl_error($c);
$error_nr = curl_errno($c);
curl_close($c);
if ($error_nr != 0) {
echo "info1:error ".$error_nr;
}
else if ($http_code == 200) {
return $response;
} else {
echo "info2:error ".$http_code;
}
}
?>
Above words have shown the basic usage of VeryPDF Web to PDF Converter Cloud API, and please do not hesitate to contact us when you have any questions.