Hi,
I’ve been playing around with creating dynamic PDF files using fpdf with EE.
The sample code below will work if it is a stand-alone php file, but when it’s an expression engine template, it will just send the raw PDF source to the web browser.
The following code:
<?php
require('fpdf16/fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',72);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
Creates:
%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T07�30PISp �Z*���뙛+��(hx����+���(j*�d���\ endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R >> /XObject << >> >> endobj 6 0 obj << /Producer (FPDF 1.6) /CreationDate (D:20110505184026) >> endobj 7 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 8 0000000000 65535 f 0000000230 00000 n 0000000418 00000 n 0000000009 00000 n 0000000087 00000 n 0000000317 00000 n 0000000522 00000 n 0000000597 00000 n trailer << /Size 8 /Root 7 0 R /Info 6 0 R >> startxref 700 %%EOF
If I save that page and then change the extension to pdf and open it, it works as a PDF.
Anyone with any ideas of how to create the pdf so it opens in the browser as a pdf?
I’m guessing that it might have something to do with altering the HTTP headers?
Thanks 😊