gpt4 book ai didi

php - 使用php将动态html加载到dompdf中

转载 作者:行者123 更新时间:2023-11-29 13:02:37 25 4
gpt4 key购买 nike

你好,我正在编写一个脚本,它将使用file_get_contents动态加载html,并在服务器上生成和保存pdf,但不知何故,我的php文件给了我500内部服务器错误 那么还有其他方法可以将 html 加载到 dompdf 中吗这是我的代码

<?php
error_reporting(E_ALL);

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');
require_once("dompdf_config.inc.php");

$mvouch = $_REQUEST["vouchno"];
$dompdf = new DOMPDF();
$html =file_get_contents("http://www.myurl.com/project/file_to_be_loaded.php?vouchno=$mvouch");
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents("/files/report.pdf", $output);
echo "<h1>DONE!!!</h1>";
?>

最佳答案

这应该可以!

<?php
error_reporting(E_ALL);

require('includes/check_auth_user.php');
require('includes/dbconnect.php');
include ('includes/function.php');
require_once("dompdf_config.inc.php");

$dompdf = new DOMPDF();

require_once('file_to_be_loaded.php?vouchno='.$mvouch');

$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents('/files/report.pdf', $output);
echo '<h1>DONE!!!</h1>';
?>

也许您还希望报告文件有一个动态文件名,并按年/月对文件夹进行排序

$month  = date('Ym');
$date= Date("Y-m-d");
$time = Date("His");
$filename = 'files/'.$month.'/report'.$date.'_'.$time.'.pdf';
if (!is_dir("files/".$month)) {
// dir doesn't exist, make it
mkdir("files/".$month);
}
file_put_contents($filename, $output);

file_to_be_loaded.php - 应该看起来像这样

$html = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<html lang="sv">
</head>
<body>';
$html .='<h2>Report</h2>';
$html .='
</body>
</html>';

关于php - 使用php将动态html加载到dompdf中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23126351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com