Fix mPDF Files That Open in Browsers but Not Adobe Acrobat
Question details
Diagnose an mPDF-generated file that displays in a browser but cannot be opened in Adobe Acrobat.

- Product
- mPDF and Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A user generates a PDF with mPDF and wants it to open in Acrobat as well as a browser.
- Observed behavior
- The file displays in a browser, but Acrobat reports that its file type is unsupported or that it is damaged.
Save the generated file locally and locate the PHP script that creates the mPDF response. You will need a text editor and access to the server's PHP error logs.
Inspect and correct the generated PDF output
Use this method to identify HTML, PHP warnings, or other stray output that may make the PDF invalid.
Open the downloaded file in a text editor such as Notepad and check its beginning. A properly generated PDF should start with a header such as %PDF.
Check the beginning of the file for HTML, PHP warnings, error messages, or other text before the PDF data. If the file contains an error page instead of PDF data, investigate the message in that page.
In the PHP script that generates the file, remove debug output, stray whitespace, and other content sent before the mPDF output. Fix any reported PHP errors and configure errors to be logged rather than displayed in the PDF response.
Run the PDF generation action again, save the new file, and open it in Adobe Acrobat. If it still fails, check the server's PHP error logs and validate the regenerated PDF.

View Valid PDF Files and Office Documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for viewing valid PDFs and working with Office documents. Its format compatibility makes it easy to move existing files into WPS. It cannot repair invalid mPDF output, which must be corrected at the source.

Frequently Asked Questions
Why does the PDF open in my browser but not in Acrobat?
Browsers and Acrobat may handle malformed PDFs differently. Open the saved file in a text editor and look for a %PDF header and any unexpected text before it.
What if the downloaded PDF contains PHP warnings?
Use the warning text and your server's PHP error logs to identify and fix the underlying issue. Configure PHP to log errors rather than display them in the PDF response, then generate the file again.
Will setting Content-Type to application/pdf fix the file?
No. Set the appropriate Content-Type in the HTTP response, but also ensure the response contains valid PDF data without stray HTML, warnings, or other output.
Can WPS Office repair an invalid mPDF response?
WPS Office can open valid PDFs, but it does not fix invalid output from the mPDF generation script. Correct the script and regenerate the file first.




