Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PHP生成网页后获取网页的DOM/HTML_Javascript_Php_Html_Pdf_Dom - Fatal编程技术网

Javascript PHP生成网页后获取网页的DOM/HTML

Javascript PHP生成网页后获取网页的DOM/HTML,javascript,php,html,pdf,dom,Javascript,Php,Html,Pdf,Dom,我正在尝试从PHP页面生成PDF。我有下面的代码,它的工作。然而,当我像其他人一样尝试使用ob_get_clean()时,我会得到一个500错误 关于我可以获得已生成页面的其他方法的想法?Javascript能工作吗 另一个问题是,该页面需要登录,并且也是由POST表单生成的,因此该页面不容易抓取 </html> <?php $content = "This will work";//ob_get_clean(); require_once dirname(__FILE__).

我正在尝试从PHP页面生成PDF。我有下面的代码,它的工作。然而,当我像其他人一样尝试使用ob_get_clean()时,我会得到一个500错误

关于我可以获得已生成页面的其他方法的想法?Javascript能工作吗

另一个问题是,该页面需要登录,并且也是由POST表单生成的,因此该页面不容易抓取

</html>
<?php
$content = "This will work";//ob_get_clean();
require_once dirname(__FILE__).'/html2pdf/vendor/autoload.php';

use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;

try {

    //ob_clean();
    $html2pdf = new Html2Pdf();
    $html2pdf->writeHTML($content);
    $html2pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/output.pdf', 'F');
} catch (Html2PdfException $e) {
    $formatter = new ExceptionFormatter($e);
    echo $formatter->getHtmlMessage();
}


?>

如果您的服务器允许fopen或use,您可以使用(对我来说是通用的最佳方法):


如果是500,您的错误将出现在错误日志中。它说了什么?我查看了一下,没有发现任何东西。检查phpinfo()并查看错误日志设置在哪里,甚至可以在脚本中设置一个带有ini_设置的自定义日志。。另外,请确保错误报告设置为-,然后重试。
</html>
<?php
require_once dirname(__FILE__).'/html2pdf/vendor/autoload.php';
$content = file_get_contents('yourphppage.php'); //first option
//OR CURL MODE
$c = curl_init('yourpage.php');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
//curl_setopt(... other options you want...)

$content = curl_exec($c);

if (curl_error($c))
    die(curl_error($c));

// Get the status code
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);

curl_close($c);
//execute your code bellow checking $status of cURL, else thrown an error

use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;

try {

    //ob_clean();
    $html2pdf = new Html2Pdf();
    $html2pdf->writeHTML($content);
    $html2pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/output.pdf', 'F');
} catch (Html2PdfException $e) {
    $formatter = new ExceptionFormatter($e);
    echo $formatter->getHtmlMessage();
}

?>
var doc = new jsPDF();

// We'll make our own renderer to skip this editor PS: An example if you want to take out some elements from the renderer
var specialElementHandlers = {
    '#editor': function(element, renderer){
        return true;
    }
};

// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML($('body').get(0), 15, 15, {
    'width': 170, 
    'elementHandlers': specialElementHandlers
});