portabletelly Posted April 22 Share Posted April 22 Just doing some research on Coverting HTML content quotes into PDF. Allot of what I read and watched is pointing to using composer then a tool like dompdf. For the guru's out there what would you recommend to turn a page like the below with a customers name quote number and 10 to 20 line items and then some totals into a pdf document. I eventually want to have some type of cron job run a task and email pdfs out. Most quotes will be a single page but project quotes will go over to 2 pages. I don't really want to muck around installing composer but before I go too far down the garden path with this section I thought I'd get some feedback on the best way/path to go for php pdf generation for things like quotes and invoices. Option 1. mPDF Options 2. jsPDF Options 3. Puppeteer Option 4. Dompdf This is basic example of the data to go on the quote. Quote Link to comment https://forums.phpfreaks.com/topic/327475-pdf-recommendations/ Share on other sites More sharing options...
gizmola Posted Monday at 06:33 AM Share Posted Monday at 06:33 AM What's the problem with installing composer? Takes 2 seconds, and that is what PHP uses for dependency management and autoload building. Every option you have is going to start with using composer, and not using it is going back to PHP development as it was done in the bad old days of copying entire library codebases into project directories and everything that was painful, error prone and annoying with PHP library use, as of 10+ years ago. As for "best path" there really isn't one. There are different technical approaches to the problem, that tend to have different requirements, gotchas and limitations. You are best off doing a quick evaluation using the html docs you already have to explore the libraries. One up and coming option you didn't mention is gotenberg: a sophisticated go based conversion engine that has a php api. It has a lot going for it, but also has more moving parts. Here's the PHP Api that lets you talk to the Gotenberg server: https://github.com/gotenberg/gotenberg-php Puppeter (or rather the PHP api to it) takes a similar approach, in that it's a bridge to a headless browser used to render a page, which then allows you to save a pdf version. The https://github.com/zoonru/puphpeteer library is still being maintained, but already it's a fork of the original. You also have more moving parts (depending on Node, and the rialto bridge to Node). jspdf has similar issues, being a js library. For the Pure PHP library options, I'd start with dompdf and see if that works for you. Known limitations are the lack of support for flexbox or grid, so that might be a deal breaker. I probably wouldn't use mpdf, due to the age and lack of updates. It's a fork of fpdf. With that said, not unlike dompdf, if you constrain your html it might be fine for your use case, but the lack of updates is not a great sign. Along those same lines, lots of people are still using Snappy https://github.com/KnpLabs/snappy particularly with Laravel or Symfony, since there are integrations for both of those, but it does depend on a https://wkhtmltopdf.org/ which is now a dead project, even though you can still get builds of it for most linux distros. Quote Link to comment https://forums.phpfreaks.com/topic/327475-pdf-recommendations/#findComment-1653480 Share on other sites More sharing options...
Psycho Posted Wednesday at 08:08 PM Share Posted Wednesday at 08:08 PM In a past life, have experience turning dynamic, user generated content via a web page into print-ready PDFs for commercial printing. In that case, the user input on the web forms was converted into PostScript code that was then run through a processing engine (my expertise was in the postscript programming). So, when I had a need to generate PDFs as a PHP hobbyist, I looked for a solution where I could "program" the creation of the PDF in the same way as I did with PostScript. I ended up using the FPDF Library. If you have fairly rigid constraints on the layout of the content, this could be an option. Instead of generating an HTML page and running that through something to convert it to a PDF, this library allows you to create a PFD file in much the same way you would create a web page. I.e. determine "where" on the page you want to put an element, define things like color, font, and then place the elements on the page. However, there is another, simpler option. Instead of emailing the user a PDF, just send the user a link. That link would be to a web page of their quote and then the user can print the web page quote to PDF, the printer, or however they want. I think most shopping sites I use have this approach if I want to print the invoice. This much simpler and less moving parts, IMO. Quote Link to comment https://forums.phpfreaks.com/topic/327475-pdf-recommendations/#findComment-1653554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.