我正在尝试从textarea中获取一些html,并将其转换为pdf格式。我从https://github.com/dompdf/dompdf下载了DOMPDF,并写了下面的代码。当我点击提交时,我得到了这个错误:“内部服务器错误”。(我的webhost没有告诉我是哪一行)(这个文件的名称是test2.php)
<?php
if (isset($_POST['submit'])) {
$content = $_POST['content'];
if (empty($content)){
$error = 'write something';
}
else {
include_once( 'dompdf/dompdf_config.inc.php' );
$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->render();
$dompdf->stream('example.pdf');
}
}
?>
<!DOCTYPE html>
<head>
</head>
<body>
<?php
if(isset($error)){
echo $error;
}
?>
<form method="post" action="test2.php">
<textarea name="content" id="content">hello world</textarea><br>
<input type="submit" name="submit" value='submit'>
</form>
</body>
</html>发布于 2019-11-21 19:06:54
我花了一个多月的时间来解决这个问题。最后我解决了这个问题。解决方案如下。
<?php
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
?>
<html>
<head></head>
<body>
<h1>Sucess</h1>
</body>
</html>
<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->setPaper('A4', 'portrait');
//$dompdf->setPaper('A4', 'landscape');
$dompdf->load_html($html);
$dompdf->render();
//For view
$dompdf->stream("",array("Attachment" => false));
// for download
//$dompdf->stream("sample.pdf");
?>发布于 2013-05-19 16:06:11
当我在一个项目中使用DOMPDF时,我在客户服务器上遇到了类似的问题。
您可能没有为您的PHP安装配置正确的错误报告级别。
在脚本的顶部放置以下内容:error_reporting(E_ALL);
示例:
error_reporting(E_ALL);
if (isset($_POST['submit'])) {
$content = $_POST['content'];
if (empty($content)){
$error = 'write something';
}
else {
include_once( 'dompdf/dompdf_config.inc.php' );
$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->render();
$dompdf->stream('example.pdf');
}
}现在,您应该会看到有关收到的错误类型的更详细消息。
传递给$dompdf->load_html($content);方法的HTML标记可能有问题,或者您可能遇到与内存相关的问题(超出了您的内存限制)。
通常情况下,这些错误会自行报告,但根据您的设置,报告可能会受到限制。
https://stackoverflow.com/questions/16629682
复制相似问题