我的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,我看到了图像,但就是这样……有什么建议吗?非常感谢。
您正在将图像读入一个变量并将其传递给dompdf。因此,dompdf将构成图像的文本视为HTML源。由于您的图像可以从存储在 $LgPath 你应该可以这样做:
$LgPath
<?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"); ?>