"Network failure" to download PDF generated with with PHP FPDF/FPDF2File class in Google Chrome

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!

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'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;

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

Comments
  • maybe do you solve this problem?
  • No. It still without a solution.
  • i create a little solution maybe is a solve for you, i create or run the report on window.open
  • and then solve the problem for me i can get the download option without problems
  • window.open(...) works for me with chrome and dyanic generated pdf !!! thanks!
  • Thaks for your time. But it not work. I'm using FPDF and FPDF2File. See link at updated description.
  • 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.