Welcome Guest, Not a member yet? Register   Sign In
Issue when combining Apache2, PHP 7.4 FPM and DomPDF
#1
Bug 

Hello, the problem is a very specific case, although I am not sure what's causing it.

I have a local server environment which uses:

  • Windows 10 x64
  • Apache 2.4.25 x64
  • PHP 7.4.11 
  • Dompdf 1.0.2
I use the dompdf library (tried both via composer and as a required library) to generate PDFs with user data. A basic example of code would be something like this:
PHP Code:
public function test()
{

    
$dompdf = new \Dompdf\Dompdf();
    
$dompdf->loadHtml('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>Solicitud en PDF</title></head><body><h1>Hola</h1></body></html>');

    
$dompdf->setPaper('Letter''portrait');

    
// Render the HTML as PDF
    
$dompdf->render();

    
// Output the generated PDF to Browser
    
$dompdf->stream("test.pdf",array('Attachment'=>0));



Now on my local server, using both via composer and as a required library, this process works fine and I get this:

[Image: testpdf.png]

On the other hand, my production environment has:
  • Ubuntu 20.04 LTS
  • Apache 2.4.41 - Apache uses FPM and http/2
  • PHP 7.4.3
  • Dompdf 1.0.2



I thought this part was working, but then I started getting reports that users are not getting PDFs but scrambled letters and symbols. So I tried to see what's happening and I got this. 

[Image: testpdferror.png]
This literally comes out as the PDF code.

If I copy this function outside my CodeIgniter instance on the same server, just using a regular php file and requiring the library, there's no problem. So, for some reason I get a problem when those three are combined: 
  • CodeIgniter 4.1.1
  • PHP 7.4 FPM
  • DomPDF 1.0.2
As I said before if I remove CodeIgniter from this combination on the production server it works. 

I also tried with PHP 8, to check if it was a PHP issue, same result.

My theory is that it might be some header issue, because the file is output as text and not PDF.
Reply


Messages In This Thread
Issue when combining Apache2, PHP 7.4 FPM and DomPDF - by mi_ov - 03-18-2021, 05:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB