[Gambas-user] How to reduce the size of PDFs generated with PDFSurface/Cairo

Claus Dietrich claus.dietrich at freenet.de
Mon Oct 9 21:51:19 CEST 2023


> On 9th Oct Fabien Bodard gambas.fr at gmail.com wrote:
> Pdf size is a big deal fore too.
> I will have a look

>> Le lun. 9 oct. 2023 à 10:10, BB <adamnt42 at gmail.com  <http://lists.gambas-basic.org/listinfo/user>> a écrit :

>>//>>/On 30/9/23 1:05 am, Claus Dietrich wrote: />>//>>/Hi />>//>>/I am using the Gambas PDFSurface and Cairo to generate and assemble />>/multi-page PDFs. />>//>>/When I insert a jpg-image from my scanner (A4 size, 300dpi, 90% quality) />>/with a size of 730 kB the resulting single page PDF is blown up to a size />>/of 2.8 MB. A stripped down demo project is attached: />>//>>/https://send.vis.ee/download/62247b9c0d0529a1/#JidKAJn64IdF4G1c-4B07A />>//>>/Does anyone know a way to obtain a PDF file with a similar size (resp. />>/compression) like the source image by using native Gambas means (=without />>/installing tools like ImageMagick)? />>//>>/Best regards />>/Claus />>//>>//>>/----[ http://gambaswiki.org/wiki/doc/netiquette ]---- />>//>>/Hi Claus, I don't see that you ever got a reply on this, so just a bit of />>/information from me on it. I don't know how you could reduce the size as />>/from my "memory" pdf used to and maybe still does include all kinds of />>/images as a dot-by-dot set of "portable" print instructions. That is for />>/each image pixel it creates approximately 4 pdf (byte code) statements. />>/Years ago I remember I had to tell the (ahem) "less experienced" graphics />>/designers never to use any shade of yellow in their pictures as that blew />>/the pdf size out by about 64 bytes per pixel i.e about 32 times the 
size of />>/the image. So 4 times the original image size would be a "good outcome" in />>/my opinion. As far as I know pdf still doesn't know fig-all about image />>/formats. />>//>>/hth />>//>>/b Hi The PDF surface seems to blow up the pixel graphics as required by 
its dimensions. Hence the format or the source (png or jpg) doesn't play 
a decisive role. So I decided to go for the best quality by always using 
png-graphics and after the PDF is generated with the PDFSurface I now 
compress it with a ghostscript shell command. I simply use the parameter 
-dPDFSETTINGS, i.e. ///-dPDFSETTINGS/=150 to reduce the PDF to 150 dpi. A more sophisticated 
solution with ghostscript is described here: 
https://gist.github.com/ahmed-musallam/27de7d7c5ac68ecbd1ed65b6b48416f9 
I am not sure whether this is the best/right way, but it works and the 
results fulfil my requirements. Brgds Claus /



More information about the User mailing list