0

I'm generating a very large pdf file on my PHP application. The document can reach over 300 pages. The build process may take more than 40 seconds, that's why I want to show the user a message to understand that the file is being generated.

The problem is that when i set $this->progressBar = 1; on config.php file, the progress shows perfect, but when the proces finish, I'm only getting a Finished message, and i'm not redirected to the file.

Heres' my code:

 <?php

    ob_start(); 
include('include/mpdf/mpdf.php');
define('_MPDF_URI','../');
$mpdf = new mPDF('','A4', 9, 'freesans', 10, 10, 20, 15, 5, 5, 'L');
$mpdf->SetHTMLHeader($cabecera);
$mpdf->setFooter("Pagina {PAGENO} de {nb}");
$html=utf8_encode($html);
$mpdf->WriteHTML($html);
$mpdf->Output();
ob_end_flush();

I believe someone already has gone through this problem. Please guide me on how I can solve this problem.

Thank you,

martin.softpro
  • 435
  • 6
  • 21

1 Answers1

0

The documentation has a note:

Note: You may need to define the constant _MPDF_URI if you use progress bars. The constant _MPDF_URI is needed to redirect the user to the PDF file (and prior to mPDF 5.0 to locate a javascript file within the progress bar script). It must be either a relative path (e.g. '../') or a full URI (e.g. 'http://www.example.com/mpdf/'). If you do not define it before calling mPDF() mPDF will assign it the same value as _MPDF_PATH. This is fine if you have used a relative path. _MPDF_PATH requires either a relative path or a filesystem real path (e.g. '/homepages/27/d84233457/htdocs/')

Then make sure the ->Output() function has the correct parameters, such as:

$mpdf->Output('yourFileName.pdf', 'I');

For more info see this stack answer.

Community
  • 1
  • 1
LeonardChallis
  • 7,759
  • 6
  • 45
  • 76
  • yes, that was the first thing I tried. but then it away because it did not work. i just edited the question. – martin.softpro Oct 04 '16 at 14:25
  • there is no error. the process finish correctly, but ir won't redirect to the file – martin.softpro Oct 04 '16 at 14:37
  • Sorry, i'm getting this on the google chrome console: Not allowed to load local resource: file:///C:/xampp/htdocs/cl25demayo/include/mpdf/progbar.css Not allowed to load local resource: file:///C:/xampp/htdocs/cl25demayo/include/mpdf/includes/out.php – martin.softpro Oct 04 '16 at 14:52
  • Hi, you double check the _MPDF_URI?, it should be a valid URL or a valid relative url, not a system path, your problem is clasic when the _MPDF_URI is not set correctly, it generate the pdf but can't redirect because the URI does not exist – Cesar Oct 04 '16 at 14:59
  • yes, I've checked at all. now I managed to redirect the PDF, but it opens named "out.php" then, if the user downloads it, the file downloads as "out.php" – martin.softpro Oct 04 '16 at 15:56
  • I've updated my answer - check the `Output()` method. – LeonardChallis Oct 04 '16 at 16:54
  • I have already tried, but it is not the solution, since the default values ​​are "mpdf.pdf" and "I". Looks like this is an issue of mpdf when using progress bar... – martin.softpro Oct 04 '16 at 17:18