WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

Improve flex rendering speed

Open AliShahbazzz opened this issue 5 years ago • 8 comments

After trying all python libraries to generate a pdf, I've found the best one "Weasyprint". This is the only one library that generates a perfect pdf file for my html and css. But the problem is, it takes too long. I've read other issues regarding performance and came to a conclusion that, may be due to the flexbox the generation is taking too long. I've tried filtering my css but no luck. The time taken is around 15-25 seconds for the below code. Any suggestions to improve time and have no effect on quality are appreciated.

html.txt

AliShahbazzz avatar Jul 17 '20 19:07 AliShahbazzz

Hello!

You’re right, this document take a lot of time to render. Logs tell that the problem comes from the layout part, I have to check what’s taking so much time.

liZe avatar Jul 18 '20 10:07 liZe

The rendering is slow because of the nested flex layouts. Flex layout is not really optimized, but it shouldn’t be that slow…

liZe avatar Jul 18 '20 11:07 liZe

Thank you for your time and reply. Will be waiting. :)

AliShahbazzz avatar Jul 18 '20 17:07 AliShahbazzz

I've found an alternative to flex layout and used it in my code and the PDF generation time has improved a lot.

If someone came across the same problem, here's what I used:

'display: flex' -> 'display: inline-block' 'flex-direction: column' -> 'display: block'

There's a detailed list in here: https://kyusuf.com/post/almost-complete-guide-to-flexbox-without-flexbox/

As I found an alternative solution, I'm closing the issue.

AliShahbazzz avatar Jul 24 '20 16:07 AliShahbazzz

I've found an alternative to flex layout and used it in my code and the PDF generation time has improved a lot.

:+1:

Thanks a lot for your solution!

As I found an alternative solution, I'm closing the issue.

I reopen it and change the title: we have to find why flex layout is slow :smile:.

liZe avatar Jul 24 '20 18:07 liZe