将同一页面转换为PDF

时间:2016-11-20 14:39:23

标签: php laravel

我想将同一个文档转换为PDF,或者我想在url中添加post方法,如:

$dompdf->loadHtml($_POST['name']);

以下是代码:

<?php
// include autoloader
require_once 'dompdf/autoload.inc.php';

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();

$dompdf->loadHtml(file_get_contents('http://localhost/));

// (Optional) Setup the paper size and orientation
$dompdf->setPaper(array(0,0,850,2250), 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
//$dompdf->stream();

// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("codex",array("Attachment"=>0));
?>

1 个答案:

答案 0 :(得分:-3)

如果file_get_contents

,你会遗漏单行引号
<?php
// include autoloader
require_once 'dompdf/autoload.inc.php';

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();

$dompdf->loadHtml(file_get_contents('http://localhost/'));

// (Optional) Setup the paper size and orientation
$dompdf->setPaper(array(0,0,850,2250), 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
//$dompdf->stream();

// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("codex",array("Attachment"=>0));
?>