Python Forum
FPDF question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: FPDF question (/thread-30585.html)



FPDF question - DPaul - Oct-27-2020

I have an app that generates pdfs, i use it on a regular basis, using FPDF.
It works fine, thank you.

Recently I did a version 2, the big difference being that i put a second image on the one page each pdf has.
The first image is rater small , a jpg of 300x188 pixels.
The new one is bigger, a png of 1200 x 1000 pixels, that is rendered a bit smaller on the page.
But now, instead of instantaneous, it takes like 20 seconds to finish all my pages.(19 pdfs in total)
The code is not very tricky for either of them:

pdf1.image(foto1, x=10, y=15, w=50)
..... 
pdf1.image(foto2 , x=20, y=150, w=150)
Before you start telling me i should be using another package, my question is,
a) Is the size of the picture causing the delay?
b) is a png slower than a jpg. It is produced using matplotlib, maybe i could resize it.

The only thing that could convince me to walk away from FPDF, is that elsewhere
the page layout syntax would be much easier. I spent a lot of time puzzling to get
the headers on top of the right columns. Smile
thx,
Paul


RE: FPDF question - Gribouillis - Oct-27-2020

My suggestion is

a) Try and see if it is faster with a smaller image (probably true)
b) Try and see if it is faster with a jpg (probably not)

There are innumerable ways to resize the image: PIl, imagemagick...


RE: FPDF question - DPaul - Oct-27-2020

I have been running various tests and searches since my post.

The standard output (save) for matplotlib is .png.
What i did not know is that when Pillow is installed, you can also use .jpg. (Without doing any extra import at all)
I happen to have Pillow, so i did the test with exactly the same code, just with the extension changed.

Instantaneous ! Like it was before.
So my conclusion must be that in this case (FPDF) jpgs are much much faster.

Worth examining if this can be generalised to other types of apps with matplotlib involved.
Paul