-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to save to pdf #3643
Comments
Rather than using the helper, which is there as an abstraction to simplify the sample code, use the actual Writers as described in the documentation. We do provide the documentation for a reason. IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf::class);
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf($spreadsheet);
$writer->save("Save_Path/FileName_that_I_Want_to_Use_for_the_Saved_File.pdf"); |
I already understood how to create a file, thanks, but it somehow saves it wrong even when I try to save it simply to the server when opening the file, it gives a reading error
|
That doesn't really help to diagnose any problem. The PDF Writers all work the same way, they generate an HTML file, and then use the relevant PDF library functions to convert that HTML to PDF. Can you use the HTML Writer to generate an html file and see what that looks like? Or try opening the generated PDF file in a text editor, and see if there is any obvious problem in there, such as a PHP error message |
At a guess, as the images look broken, your image path is wrong |
I fixed it, but the pdf still won't open When I try to save to the server (localhost), I get this error, maybe that's why it creates a broken pdf file?
|
That sounds like you don't have the mpdf library installed |
No! That is not an error in our code. As per the documentation, you need to install the mpdf library; that line of code is instantiating the class from that external library... external meaning that it isn't included as part of PhpSpreadsheet. |
Install the mpdf library using composer, then use the PhpSpreadsheet documentation to send your spreadsheet to PDF The Writer\Pdf\Mpdf.php wrapper handles all the generation of the HTML, and sending it to the Mpdf library |
Problem seems resolved, no update in over a year, closing. |
Which versions of PhpSpreadsheet and PHP are affected?
1.28 \ 7.4
hello, how can i save the pdf file ? I use your code but it doesn't work for some reason
I looked at examples like this samples
I looked through the files from the first to the sixth, but did not understand how to save the data in pdf
The text was updated successfully, but these errors were encountered: