How to use TCPDF to output pdf file in browser without saving like in ezpdf?
8 Answers
Use I
for "inline" to send the PDF to the browser, opposed to F
to save it as a file.
$pdf->Output('name.pdf', 'I');

- 9,000
- 9
- 39
- 43
-
1how do i send the output pdf as email attachment? – alex Feb 15 '13 at 13:42
-
1User $pdf->Output('name.pdf', 'E') as per tcpdf documentation in "http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1" E: return the document as base64 mime multi-part email attachment (RFC 2045) – wingskush Sep 14 '15 at 10:25
This is what I found out in the documentation.
- I : send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
- D : send to the browser and force a file download with the name given by name.
- F : save to a local server file with the name given by name.
- S : return the document as a string (name is ignored).
- FI : equivalent to F + I option
- FD : equivalent to F + D option
- E : return the document as base64 mime multi-part email attachment (RFC 2045)

- 889
- 10
- 10
-
1
-
Strange, using PHPMailer to send the PDF as an attachment, the file is corrupted if I use "E", but produces a functional PDF if I use "S", but with "S" none of the images are visible in the PDF. – Josh Jun 25 '21 at 01:11
-
I have a similar issue.... I implemented : `$pdf->Output(__DIR__ . '/mytestfile.pdf', 'FD');` as like as `$pdf->Output(__DIR__ . '/mytestfile.pdf', 'D');` but browser's doesn't open download window to get the PDF... could maybe be related to some php download settings ? if yes, which option I should look at ? – Luigino Apr 22 '22 at 10:53
If You want to open dialogue window in browser to save, not open with PDF browser viewer (I was looking for this solution for a while), You should use 'D':
$pdf->Output('name.pdf', 'D');

- 1,529
- 3
- 18
- 42
Print the PDF header (using header() function) like:
header("Content-type: application/pdf");
and then just echo the content of the PDF file you created (instead of writing it to disk).

- 2,965
- 2
- 25
- 34
I've been using the Output("doc.pdf", "I");
and it doesn't work, I'm always asked for saving the file.
I took a look in documentation and found that
I send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF. http://www.tcpdf.org/doc/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1
Then I think you have to use a plugin to print it, otherwise it is going to be downloaded.

- 6,836
- 2
- 26
- 47

- 95
- 11
-
1The "plug-in" referred to in the documentation you're quoting is the browser plugin. If your browser doesn't have a PDF viewer plugin (or built-in support), you'll probably be prompted to download it - but that depends on the behaviour of the browser in question. – NullColaShip Jul 01 '16 at 06:03
It works with I
for inline as stated, but also with O
.
$pdf->Output('name.pdf', 'O');
It is perhaps easier to remember (O
for Open).
$filename= time()."pdf";
//$filelocation = "C://xampp/htdocs/Nilesh/Projects/mkGroup/admin/PDF";
$filelocation = "/pdf uplaod path/";
$fileNL = $filelocation."/".$filename;
$pdf->Output($fileNL,'F');
$pdf->Output($filename, 'S');