Php html2pdf包含来自页面的html

Php html2pdf包含来自页面的html,php,html2pdf,Php,Html2pdf,正在尝试使用生成PDF。我可以通过在函数本身中创建标记来创建PDF,但我真正想做的是使用URL从单独的文件中包含标记 我的代码生成了一个PDF,但是PDF是空的,我假设这意味着没有从指定的url提取HTML require_once('html2pdf/html2pdf.class.php'); $mlsnum = $_GET['mlsnum']; $url = 'http://www.nexthometown.com/components/com_singleprop/views/single

正在尝试使用生成PDF。我可以通过在函数本身中创建标记来创建PDF,但我真正想做的是使用URL从单独的文件中包含标记

我的代码生成了一个PDF,但是PDF是空的,我假设这意味着没有从指定的url提取HTML

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');
有人熟悉html2pdf吗?我已经阅读了文档和示例,但是我找不到任何有关此方法的参考。我已经找到了这个定义,但它说的不多。

此库用于帮助创建PDF文件,而不是直接转换HTML页面。 您不能使用
标记。

此库用于帮助创建PDF文件,而不是直接转换HTML页面。
不能使用<代码> <代码>、代码> <代码>、<代码> <代码>标签。

问题有点老了,但这就是我如何从GeTtMLFabPage方法解决空白页的方法。我没有使用getHtmlFromPage方法,而是简单地使用curl来获取我想要的pdf页面,然后将其作为字符串传递给html2pdf

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;
        }
    }
}

这个问题有点老,但这就是我如何从GeTtMLFabPage方法解决空白页的方法。我没有使用getHtmlFromPage方法,而是简单地使用curl来获取我想要的pdf页面,然后将其作为字符串传递给html2pdf

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;
        }
    }
}

我明白了,但在他们的wiki中,对于最新版本,他们有一种方法可以做到这一点:我正在尝试获取有关该功能的帮助,如标题所述。尝试从
标记内部获取标记。。。我想这应该是可行的,但在他们的wiki中,对于最新版本,他们有一种方法可以做到这一点:我正在尝试获取有关该功能的帮助,如标题所述。尝试从
标记内部获取标记。。。我觉得应该行得通