Reputation: 35
I'm using codeigniter framework and dompdf to generate pdf . It works totally fine on localhost but shows 500 error when on live server. I've tried debugging but it doesnt shows any errors in error_log file. Here is the code of the function generate_pdf.
public function generate_pdf($content, $name = 'download.pdf', $output_type = null, $footer = null, $margin_bottom = null, $header = null, $margin_top = null, $orientation = 'P')
{
$this->load->library('pdf');
$html = '';
if (is_array($content)) {
foreach ($content as $page) {
$html .= $header?'<header>'.$header.'</header>':'';
$html .= '<footer>'.($footer?$footer.'<br><span class="pagenum"></span>' : '<span class="pagenum"></span>').'</footer>';
$html .= '<body><div class="page">'.$page['content'].'</div></body>';
}
} else {
$html .= $header?'<header>'.$header.'</header>' : '';
$html .= $footer?'<footer>'.$footer.'</footer>' : '';
$html .= $content;
}
$this->pdf->set_option('isPhpEnabled', true);
$this->pdf->set_option('isHtml5ParserEnabled', true);
$this->pdf->set_option('isRemoteEnabled', true);
$this->pdf->set_option('enable_html5_parser', TRUE);
// $this->pdf->set_option("DOMPDF_ENABLE_HTML5PARSER", true);
// $this->pdf->loadHtml($html);
$html = preg_replace('/>\s+</', '><', $html);
// $this->pdf->loadHtml($contents);
$this->pdf->loadHtml($html);
// $dompdf->load_html($html);
$this->pdf->setPaper('A4', ($orientation == 'P' ? 'portrait' : 'landscape'));
// $dompdf->set_option('enable_html5_parser', TRUE);
$this->pdf->render();
// $this->pdf->stream("dompdf_out.pdf", array("Attachment" => true));
// exit(0);
if ($output_type == 'S') {
// $output = $dompdf->output();
$output = $this->pdf->output();
write_file('assets/uploads/' . $name, $output);
return 'assets/uploads/' . $name;
}
else {
$this->pdf->stream($name);
return true;
}
}
This is the error which i get:
An uncaught Exception was encountered
Type: ParseError
Message: syntax error, unexpected '='
Filename: /app/third_party/dompdf/src/Dompdf.php
Line Number: 356
Upvotes: 1
Views: 1720
Reputation: 132
If you are using Dompdf 0.8.5, This is your Exception's line
[$this->protocol, $this->baseHost, $this->basePath] = Helpers::explode_url($file);
If this works on localhost but not on live server, this is probably a problem with PHP version since this line uses a new syntax introduced in PHP 7.1
Upvotes: 1