7

I have reports generated in PHP / FPDF / FPDF2File that are usually displayed in the browser window.

Notice:

  • The parameters are passed to the PHP that generates report POST.
  • The file is being accessed exclusively via HTTPS with a valid certificate.
  • The web server is able to log all errors and errors are being properly recorded in the log, but no error related to that FPDF/PHP is being recorded. (Ie I clean the error log, run the report and no error appears in the log ... forcing a mistake on purpose and it is registered). Thus, it seems that there is no syntax error.
  • The Content-type used is: header ( 'Content-type: application / pdf'); The problem occurs in Windows computers with Google Chrome (tested on multiple machines).
  • All buttons of the PDF rendering plug-in browsers (save, print, rotate, zoom, etc.) work normally. Except the save button in Google Chrome (in other browsers work normal).

When trying to save the PDF already opened and displayed on Google Chrome, the following error occurs:

Failure - Network error

Therefore, you can not save the PDF, unless you go to print and print in PDF, or print the PDF PDF, which does not make much sense.

Could someone tell how to solve this error?

Thanks a lot!

Allan Andrade
  • 670
  • 10
  • 26

4 Answers4

5

Do you set the no-store property of the Cache-Control header?

I don't know why, but for me it worked after changing

header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");

to

header("Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0");

Amryn
  • 51
  • 1
  • 3
0

@Amryn's answer actually worked for me. Here's my full header setup:

header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="relatorio-clientes.pdf"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . strlen(ltrim($content)));
header('Accept-Ranges: ' . strlen(ltrim($content)));

echo $content;
Mateus Neves
  • 304
  • 5
  • 16
  • 1
    `post-check` and `pre-check` are meaningless directives and should be removed. `must-revalidate` is almost never what you want. `Content-Transfer-Encoding` should not be needed. `Accept-Ranges` is supposed to say `bytes` not a number, and it almost certainly shouldn't be added unless you've configured the server to actually support range requests. – EricLaw Apr 26 '19 at 18:10
  • This did work. Thanks. – Jagruti Jun 09 '23 at 05:49
0

If you use the Print option and Save as PDF, network error does not occur (workaround).

websky
  • 3,047
  • 1
  • 33
  • 31
0

That's works for me :

Remove all characters like space after the php close tag ?>

Found here : https://stackoverflow.com/a/13463631/2267379

Simple solution: Don't do a

return $pdf->Output('medienpass.pdf', 'D');

in your getPdf() function because the output will be wrapped up in a lot of html code.

Instead return only your pdf to the client:

die($pdf->Output('medienpass.pdf', 'D'));

user2267379
  • 1,067
  • 2
  • 10
  • 20