Invoice template (PDF) image DPI

Hi, we are playing with the PDF template and are getting on well, however image DPI appears to be an issue, by default its set to 70DPI, we have an image thats 4.8inches wide, to get it to display at the correct size on the template the image has to be 336pixels wide. This is way to low resolution as its pixelated on the page.

FPDF doesnt support vector images (WMF, EPS etc…), ive tried just about every setting in the Image command for FPDF and we cant get it to raster reduce the display size of any image above 70DPI, so how do we get a higher quality image in to the PDF template?

Many Thanks

UPDATE
We worked this out, kinda complicated to explain…

The PDF system seems to be hard coded to 70DPI, however the measurements are in mm (just to complicate it abit).

We wanted our logo to be 4.8 inches wide in the center, so without this turning in to a rocket science equation, we needed to do this with calculations in the PDF template.

For 4.8inch wide logo the pixel width needs to be 336 pixels, this is WAY to small to look any good on paper, so we saved the logo as 2016 pixels wide (6 times better resolution (70DPI * 6 = 420DPI).

To get a 2016 pixel wide image to show up correctly need to use the below maths (remember the units are mm and not inches).

2016 / 70 / 6 * 25.4
[image width] / [70DPI] / [incensed resolution] = REAL INCHES (so need to * 25.4 to get mm (as 25.4mm to 1 inch).

You might wonder how we managed to get access to the image size in the PDF, as the PDF template does not store the image log width anywhere, so we used the below PHP

list($pwidth, $pheight) = getimagesize($logo);
$logo = has the path to the image (as we stored it in the company logo section)
$pwidth = width in pixels of the real logo
$pheight = height in pixels of the real logo (this is never used, but handy to have)

$pdflogowidth = $pwidth / 70 / 6 * 25.4;
$pdflogowidth = the width in mm the logo will be on the page (as ours is 4.8inches, mm will be *25.4 (121.92mm)

Once you have that width, then you can start using the Image command in the PDF template, we used the below to get it centered.

$pdf->Image($logo, ($this->page_largeur - $pdflogowidth) / 2, 10, $pdflogowidth, 0);

$logo = the real path of the logo
$this->page_largeur = holds the total page width

The above says, page width - logo width = total space each side of the logo, then divide by 2 to work out how far in to push the logo then put it on the page (aka centered).

Your notice the use of @pdflogowidth in the image command, this is the part that SHRINKS the overside image down to the correct width we need to see of 121.92mm

1 Like

Most people don’t have the tenacity to investigate non show-stopper issues as this.
Even fewer would take the time to document them. I appreciate how long it takes.

Thanks for doing this!

2 Likes

Hi GRIFFCOMM,

I was trying to insert images in Invoice PDF (like Barcode, Signature image from card etc) and found your post interesting.

Have you tried using ODT templates to generate Barcode and Signature images…? If yes, can you kindly share how you could do that please…

thanks and regards
yesbee

Hi

ive not used Libre Office for any templates, we were looking to program them in PHP, of which this project is still live, just not had time to look at it… unable to find any staff who can program in PHP (we have employed about 7 so far!)