from Patrick Gundlach |

Reduce PDF file size

Categories: speedata Publisher

The speedata Publisher has a new (pro) feature to reduce the file size of the resulting PDF. This works by setting a maximum DPI value for bitmap images (PNG and JPG).

How does it work?

You can set the maximum DPI value of the document with

<PDFOption dpi="120" />

for example. If you now include an image which would result in a higher number of pixels per inch, the speedata Publisher automatically reduces the image size to the given width.

Example: with this 768 by 1024 pixel image (from wikitravel):

and the following layout (which just includes this image)

<Layout xmlns="urn:speedata.de:2009/publisher/en"
    xmlns:sd="urn:speedata:2009/publisher/functions/en">
    <PDFOptions dpi="120"></PDFOptions>
    <SetGrid width="1in" height="1in"></SetGrid>
    <Record element="data">
        <PlaceObject>
            <Image file="https://wikitravel.org/upload/shared//9/93/Lisbon_Tram.jpg" width="3"/>
        </PlaceObject>
    </Record>
</Layout>

The PDF width of the image is three inches, therefore the image width is now 360 pixels (120 dpi * 3 inch = 360). The height of the image is scaled accordingly (keeping the aspect ratio).

Setting Pixels PDF size (bytes)
Original 450×600 177,508
120 dpi 360×480 35,349
72 dpi 216×288 16,085

Of course the visible outcome of the images get less pleasant the more you reduce the image. For example the last image looks like this:

This is always a trade off image byte size against crisp looking images. It surely depends on your application, for example if you want to print a PDF or view it online.