0

I am using MPDF Folder to generate a PDF file from HTML/PHP. This Generation of file is very helpful for many pages but now I am facing problem recently. In Mozila FireFox, when the pdf page is generated, IT is showing in the browser in complete format. After downloading/saving the file when I try to open it in Adobe reader, it shows me A message "Adobe Reader could not open 'mpdf.php' because it is either not a supported file type or because the file has been damaged". In Chrome , I get an error message as "Failed to load PDF document". However, in some other file file where PDF is generated, it works fine. I am not able to find the solution to this, so it would be very helpful to resolve this issue.
This is the below code which call the MPDF file to generate PDF

require("MPDF/mpdf.php");

$mpdf=new mPDF('c', 'A4');

$mpdf->WriteHTML($new);

$mpdf->Output();
Amlan
  • 129
  • 1
  • 2
  • 14
  • Post a hexdump of the first Kilobyte or so of the downloaded file to make sure it is not your php source. And please remove the all caps from your title – Marged May 02 '16 at 07:04
  • seems you dowload the php file and not the pdf .. – ScaisEdge May 02 '16 at 07:07
  • @scaisEdge Downloaded format is PDF. As written, it opens in pdf for other files. But for one page, the format is not supporting. – Amlan May 02 '16 at 07:09
  • make sure there is no echo,print before $mpdf->Output(); code – Minesh Patel May 02 '16 at 07:13
  • Failed to load PDF document appear when pdf is not written properly – Minesh Patel May 02 '16 at 07:14
  • I have this PHP variable $new where HTML table is being Passed which is passed through WriteHTML. @MineshPatel – Amlan May 02 '16 at 07:19
  • put in try-catch block and write output to file( $mpdf->Output($fileName,'F'); ) to check any errors – Minesh Patel May 02 '16 at 07:24
  • I removed echo before $mpdf and it worked. Thanks. But what is the logic behind this? Please care to explain @MineshPatel – Amlan May 02 '16 at 08:31
  • 1
    @Amlan it set header application/ pdf to send pdf to browser but if you echo something before it then that will also include in pdf content and it break your pdf – Minesh Patel May 02 '16 at 08:45

1 Answers1

1

I had problems absolutely positioning a div. Displayed just fine in the browser but would not open in Adobe Reader. Reason: some warnings at beginning of generated pdf file. This fixed it for me: How to make mPDF 6.1 work with PHP 7.1.5 Basically, you have to change one line regarding the error reporting.

JoKFA
  • 11
  • 2