Jump to content
mstdmstd

Search tool to generate laravel / blade/bootstrap code into pdf

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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);

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.