[英]Unable to generate pdf using DOMPDF
I have a php file which saves two images into server and creating a pdf of this saved images using dompdf. 我有一个php文件,可将两个图像保存到服务器中,并使用dompdf创建此保存图像的pdf。 I am able to save the images into particular folder but not able to generate pdf.
我能够将图像保存到特定的文件夹中,但不能生成pdf。 could someone tell me what am doing wrong here?
有人可以告诉我这里做错了什么吗? Here is my code.
这是我的代码。
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
$data1 = $_POST['data1'];
$data2 = $_POST['data2'];
if(isset($data1)) {
$uri1 = substr($data1,strpos($data1,",")+1);
$uri2 = substr($data2,strpos($data2,",")+1);
$path =$_SERVER["DOCUMENT_ROOT"].'/divya/custom_product/sites/default/files/cart';
$id = "test";
$type ="order";
$file1 = $path .'/'.$id.'-'.$type.'1.png';
$file2 = $path .'/'.$id.'-'.$type.'2.png';
$a=base64_decode($uri1);
$b=base64_decode($uri2);
file_put_contents($file1, $a);
file_put_contents($file2, $b);
}
?>
<?php
require_once("dompdf_config.inc.php");
require_once("sites/all/modules/print/lib/dompdf/dompdf_config.inc.php");
$tbl = '<html style="margin:20px 20px 0px; padding:0;">
<body style="margin:0; padding:0;">
<table style="margin:0px 0px 5px 3px;">
<tr>
<td style="width:220px;vertical-align:top;">'.$file1.'</td>
<td style="width:220px;vertical-align:top;">'.$file2.'</td>
</tr>
</table>
</body>
</html>';
$dompdf = new DOMPDF;
$dompdf->load_html($tbl);
$dompdf->render();
$pdfoutput = $dompdf->output();
// Checks whether there is an output folder inside sites/default/files
if (!is_dir('public://output')) {
mkdir("public://output", 0777);
// Creates a folder and changes its permissions}
$filename = 'sites/default/files/output/' . 'sample.pdf'
$fp = fopen($filename, "w+");
fwrite($fp, $pdfoutput);
// Writes the pdf output to a file
fclose($fp);
?>
After going through the DOMPDF wiki here , I realized that the default mode of operation is to stream the file back to the client, not necessarily save it to a file. 通过DOMPDF维基会后在这里 ,我意识到,默认操作模式是流的文件返回给客户端,不必将其保存到一个文件中。 So I started digging around some more.
所以我开始研究更多。
This question was posted before; 这个问题以前发布过; they use similar code to you, but use the much simpler file_put_contents() to write the file.
他们使用与您相似的代码,但使用简单得多的file_put_contents()来写入文件。 It's still worth trying to write a simple text file first to that location just to rule out any file system issues.
仍然值得尝试先将一个简单的文本文件写入该位置,以排除任何文件系统问题。
在创建DOMPDF类时,您缺少了寄生:
$dompdf = new DOMPDF();
Have you enabled error logging? 您是否启用了错误日志记录? Error logs, many a times, tell you exactly what is wrong
错误日志很多次会告诉您确切的错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.