Reputation: 11
hello i'm working on a script which will dynamically load html using file_get_contents
and will generate and save the pdf on the server but somehow my php file is giving me 500 internal server error so is there any other way to load the html into dompdf
here is my code
<?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>";
?>
Upvotes: 1
Views: 6777
Reputation: 1
If you use centos as the server, this is the solution to Fatal error: Class 'DOMDocument' not found in /var/www/html/include/dompdf.cls.php on line 177
:
To install PHP-XML run the following command: yum install php-xml
To install DOM/XML run the following command: yum whatprovides php-dom
To restart Apache run the following command: service httpd restart
Upvotes: 0
Reputation: 13
This should do it!
<?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>';
?>
Perhaps you want to have a dynamic filename on the reportfile aswell and sort folders by year/MONTH
$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 - should look something like this
$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>';
Upvotes: 1