http://html2pdf.fr/en/default
This library has been made to assist in the creation of PDF files, not to directly convert an HTML page.
You can not use the <html>
, <head>
, <body>
tags.
html2pdf include html from page
Question
Trying to generate PDFs with html2pdf. I'm able to create the PDFs from creating markup within the function itself, but what I REALLY want to do is include the markup from a separate file using a URL.
The code I have generates a PDF, but the PDF is blank which, I assume, means not HTML is being pulled from the specified url.
require_once('html2pdf/html2pdf.class.php');
$mlsnum = $_GET['mlsnum'];
$url = 'http://www.nexthometown.com/components/com_singleprop/views/singleprop/tmpl/scripts/oh_usda.php?mlsnum='.$mlsnum;
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->getHtmlFromPage($url);
$html2pdf->Output($mlsnum.'.pdf','D');
Is anyone familiar with html2pdf? I've gone through the docs and the examples, but I can't find any reference to this method. I've found the definition here, but it doesn't tell much.
Solution
OTHER TIPS
the question is kinda old, but this is how I solved the blank page from getHtmlFromPage method. Instead of using the getHtmlFromPage method, I simply used curl to get the page I want to pdf and then passed that to the html2pdf as a string an voila!
require_once 'path_to_html2pdf/html2pdf/html2pdf.class.php';
$str_url = 'http://your_url_here.php';
$str_content = get_page($str_url); //get_page can be file_get_contents if your server allows for that function to open a url or a curl function that im posting down below
try{
$html2pdf = new HTML2PDF('P', 'A4', 'es');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($str_content );
$html2pdf->Output('your_file_name.pdf', 'D'); //The 'D' option downloads the pdf instead of just showing it on screen
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
//Here is the curl function for get_page
function get_page($str_url){
if(strpos($str_url, 'http://') === false){
return file_get_contents($str_url);
}else{
if(ini_get('allow_url_fopen')){
return file_get_contents($str_url);
}else{
$curl = curl_init();
curl_setopt ($curl, CURLOPT_REFERER, strFOARD);
curl_setopt ($curl, CURLOPT_URL, $str_url);
curl_setopt ($curl, CURLOPT_TIMEOUT, 30);
curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
$html = curl_exec ($curl);
curl_close ($curl);
return $html;
}
}
}