我在save.php中有以下代码:
<?php
require_once("dompdf/dompdf_config.inc.php");
$LgPath=$_POST['image'];
header("Content-Transfer-Encoding: binary");
header("Content-Type: image/png");
//header("Content-Disposition: attachment; filename=image.png");
$html = file_get_contents($LgPath);
//$html = readfile($LgPath); --only shows the image
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>
我成功地使用HTML2CANVAS一些元素的打印屏幕,然后我使用$ POST将其传递给save.php页面。我希望使用DOMPDF将该图像放入sample.pdf中。使用此代码我在sample.pdf“‰PNG”中只有这个文本,我还没有想到如何修复它。使用readfile我看到图像,但就是这样......任何建议?谢谢。
答案 0 :(得分:1)
您正在将图像读入变量并将其传递给dompdf。因此,dompdf将构成该图像的文本视为HTML源。由于您的图像可以从$LgPath
中存储的位置的PHP脚本中读取,因此您应该可以执行以下操作:
<?php
require_once("dompdf/dompdf_config.inc.php");
$LgPath=$_POST['image'];
$html = '<img src="' . $LgPath . '">';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>