Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Flex/CSS with wkhtmltopdf

Tags:

html

css

pdf

I've successfully created a list using the following answer with flexbox on my HTML page How to display 3 items per row in flexbox?

I have a need to create a PDF with this data and I'm using wkhtmltopdf (https://wkhtmltopdf.org/) which also works fine however the PDF generated has all my List Items in 1 long column instead of 3 per row.

Looks like the CSS is not being processed when the PDF generation is happening any insight is appreciated.

like image 781
UserSN Avatar asked Jul 13 '19 15:07

UserSN


People also ask

Does display flex work in PDF?

Using standard CSS flexbox, you can create a complex PDF or use your existing flexbox-based layouts and designs. Test your document with the complete code examples below, or by using our demo page.

Does Dompdf support Flex?

Dompdf does not support flexbox as of this writing (current release is 0.8. 4). Refer to issue 971 for more information. You can generate that layout with a variety of stylings, but if your content goes beyond a page in length you'll run into some quirkiness around the Dompdf rendering process.

Does Flex work in all browsers?

The flexbox properties are supported in all modern browsers.


1 Answers

This worked for me :

.row {
    display: -webkit-box; /* wkhtmltopdf uses this one */
    display: flex;
    -webkit-box-pack: center; /* wkhtmltopdf uses this one */
    justify-content: center;
}

.row > div {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
}

.row > div:last-child {
    margin-right: 0;
}

See https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1522 for more informations.

like image 180
Rajian Avatar answered Sep 23 '22 16:09

Rajian