Hi,
I just purchased the API key for HTML to PDF converter and when I test it I get an error: "[Error] Failed to get document URL". My API key is XXXXXXXXXXXXXX.
Here is the testing with API call url,
https://www.verypdf.com/search/search.php?query=pdf%20to%20word&search=1
This is the code inside of test.php,
function htmltopdfsdk()
{
$apikey = "XXXXXXXXXXXXX";
$inputfile = "https://www.verypdf.com/search/search.php?query=pdf%20to%20word&search=1";
$url = "http://online.verypdf.com/app/onlineapi/";
$postfields = "apikey=" . $apikey ."&inputfile=". $inputfile . "&type=htmltopdfsdk&--title=mywebsite";
$pdf = http_post($url, $postfields);
echo $pdf;
}
htmltopdfsdk(); // uncomment this line to convert HTML to PDF
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, 100);
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;
}
}
?>
I got this code from your website, and just replaced the api key and url. Am I doing something wrong. Please help.
Thanks,
Customer
----------------------------------------------------------------
Because your URL is contain "?" and "=" keywords, these keywords will conflict with VeryPDF Cloud API URL, so you MUST use urlencode() function to encode this URL before pass it to VeryPDF Cloud API, please refer to the function of urlencode() from following web page,
http://us2.php.net/urlencode
You can use following sample PHP code to test the encoding and decoding the URLs,
<?php
$strURL = 'https://www.verypdf.com/search/search.php?query=pdf%20to%20word&search=1';
$strURL2 = urlencode ( $strURL );
echo $strURL2 . "<br>";
echo urldecode ( $strURL2 ) . "<br><br>";
$strURL = 'http://us2.php.net/urlencode';
$strURL2 = urlencode ( $strURL );
echo $strURL2 . "<br>";
echo urldecode ( $strURL2 ) . "<br><br>";
?>
Original URL is:
https://www.verypdf.com/search/search.php?query=pdf%20to%20word&search=1
Encoded URL is:
http%3A%2F%2Fwww.verypdf.com%2Fsearch%2Fsearch.php%3Fquery
%3Dpdf%2520to%2520word%26search%3D1
You can execute following URL to convert your dynamic web page to PDF file easily,
http://online.verypdf.com/api/?apikey=XXXXXXXXXXXXX&app=html2pdf&infile=http%3A%2F%2Fwww.verypdf.com
%2Fsearch%2Fsearch.php%3Fquery%3Dpdf%2520to%2520word%26search
%3D1&outfile=verypdf.pdf
If you want to add header or footer into PDF pages, please execute following URL,
http://online.verypdf.com/api/?apikey=XXXXXXXXXXXXX&app=html2pdf&infile=http%3A%2F%2Fwww.verypdf.com
%2Fsearch%2Fsearch.php%3Fquery%3Dpdf%2520to%2520word%26search
%3D1&outfile=verypdf.pdf&--header-left=mywebsite&--footer-left=verypdf%20page
%20footer
You may refer to more options which included in html2pdf APP from following web page,
btw, if your web page contains large images, html2pdf APP may break these images, in order to handle page breaking in large images, you can put these images into a div, such as,
HTML:
<div class="Image"><img src=http://localhost/testimage.jpg></div>
CSS:
img {
page-break-inside: avoid;
}
.Image{
page-break-inside: avoid;
}
VeryPDF
hi,
I’m testing your api and i cannot get success converting this web page:
http://www.canalenergia.com.br/zpublisher/materias.asp?secao=Noticiario&id=102372
http://www.udop.com.br/index.php?item=noticias&cod=1116175
could you help?
Customer
————————————————–
You can use URLEncode() function to encode URLs first, then you can convert encoded URLs to Image files properly, e.g.,
http://online.verypdf.com/api/?apikey=XXXXXXXXXXXXX&app=html2image
&outfile=out.jpg
&infile=http%3A%2F%2Fwww.canalenergia.com.br%2Fzpublisher
%2Fmaterias.asp%3Fsecao%3DNoticiario%26id%3D102372%0A%0A%0A
http://online.verypdf.com/api/?apikey=XXXXXXXXXXXXX&app=html2image
&outfile=out.jpg
&infile=http%3A%2F%2Fwww.udop.com.br%2Findex.php%3Fitem%3Dnoticias
%26cod%3D1116175%0A
VeryPDF