mstdmstd Posted July 14, 2020 Share Posted July 14, 2020 Hello, I need some tool to generate my blade/bootstrap 4.1 code(laravel 5) into pdf with support of flexbox and css class definitions I tried spipu/html2pdf 5.2, but I did not find how it supports css class definitions... Can you advice some? With link to flexbox and css class definitions. Also I need a feature if resulting page has more 1 page to define header and footer on any page. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/311080-search-tool-to-generate-laravel-bladebootstrap-code-into-pdf/ Share on other sites More sharing options...
requinix Posted July 14, 2020 Share Posted July 14, 2020 I've used barryvdh/laravel-dompdf before and I was pleased with it. But don't go into this thinking you can use the latest HTML and CSS standards. PDFs do not work like webpages. You may have to resort to using older styles of markup and formatting. Quote Link to comment https://forums.phpfreaks.com/topic/311080-search-tool-to-generate-laravel-bladebootstrap-code-into-pdf/#findComment-1579635 Share on other sites More sharing options...
kicken Posted July 14, 2020 Share Posted July 14, 2020 I prefer using pdf-puppeteer for this job. It requires NodeJS but otherwise is fairly easy to setup. I uses a headless chrome instance to render the HTML into PDF so it supports fairly modern CSS (but not necessarily bleeding-edge). Render your template out to a temp file then pass that to the script to generate the PDF. Use a short JS script like this to handle the PDF generation const fs = require('fs'); const pdf = require('pdf-puppeteer'); const args = process.argv.slice(2); if (args.length < 2){ console.log('Usage: html2pdf source destination [options]'); process.exit(20); } const source = args[0]; const options = args.length === 2?JSON.parse(args[1]):{}; fs.readFile(source, 'UTF-8', function fileReadSuccess(err, data){ if (err){ throw err; } pdf(data, callback, options); function callback(pdfData){ console.log('PDF Data length: ' + pdfData.length); } }); Kick off the process with PHP using exec(). $cmd = $this->createCommandLine($source, $destinationPdf); exec($cmd, $output, $ret); if ($ret !== 0){ throw new \RuntimeException('Failed to generate PDF with command [' . $cmd . ']'); } $pdf = file_get_contents($destinationPdf); Quote Link to comment https://forums.phpfreaks.com/topic/311080-search-tool-to-generate-laravel-bladebootstrap-code-into-pdf/#findComment-1579636 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.