0
I have reports with generated in PHP (version 5.6) / FPDF (version 1.7) that are normally displayed in the browser window.
The following simplified example on these reports are generated:
<?php
// não fazer cache (Recomendação de Guilherme Nascimento)
$dategmt = gmdate('D, d M Y H:i:s');
header('Expires: ' . $dategmt . ' GMT');
header('Last-Modified: ' . $dategmt . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0');
header('Pragma: no-cache');
// controla se o usuário pode ter acesso ao relatório
require 'controle-acesso.php';
if(!userTemAcesso()){
echo 'Você não tem permissões para acessar este recurso';
exit;
}
require 'fpdf.php';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(40, 10, 'Olá mundo!');
// saída para arquivo não acessível diretamente via URL
$this->Output('doc.pdf', 'I');
Note:
- The parameters are passed to the PHP that generates the report via
POST
. - The file is being accessed exclusively via HTTPS with valid certificate.
- The web server is enabled to log all errors and errors are being properly logged in the log, but no errors related to this PHP are being logged. (i.e., I clear the error log, run the report and no errors appear in the log... forcing an error purposely and the same is recorded). This way, it seems that there is no syntax error.
- The
Content-type
used is:header('Content-type: application/pdf');
- The problem occurs on Windws and Google Chrome dom computers (tested on multiple machines).
- Using native Google Chrome plugin (Chrome://plugins/ -> Chrome PDF Viewer). If I disable it, it keeps downloading normal file. If active, it views everything normal, prints, but does not work the SAVE option.
All buttons of the browser PDF display plug-in (save, print, rotate, zoom, etc.) work normally. Except the save button in Google Chrome (other browsers works normal).
While trying to save the PDF open and already displayed in Google Chrome, the following error occurs:
Failure - Network error
Therefore, it is not possible to save the PDF, unless you go to print and print in PDF, ie print the PDF in PDF, which does not make much sense.
Would anyone have any idea or suggestion how to resolve this error or what might be causing the same?
Could you post a basic example of the code? I wasn’t the one who denied it, but I believe that the downvote giver had this reason.
– Guilherme Nascimento
It makes no sense
Output('I', '/var/tmp/relatorio.pdf');
, theI
serves to put the buffer in the output directly if you want to save to a file useF
, if you want to download useD
and if you want to get the buffer in a string useS
– Guilherme Nascimento
But that too is wrong
$this->Output('doc.pdf', 'I');
, you changed the order why? See the examples in the reply (I edited).– Guilherme Nascimento
is thus in the FPDF class: Function Output($name = ', $dest = '') {
– Allan Andrade
Allan which version you downloaded?
– Guilherme Nascimento
Allan which plugin is using on Chrome, is his native (PDF Viewer) or is Acrobatreader or Foxitreader?
– Guilherme Nascimento
His native: Chrome://plugins/ -> Chrome PDF Viewer (if I disable it, keeps downloading the file normally.) If active, it views everything normal, prints, but does not work the SAVE option.
– Allan Andrade
Blz, I’m gonna run the tests.
– Guilherme Nascimento