Converting TIFF to PDF Using the Datalogics PDF Java Toolkit

Converting TIFF to PDF Using the Datalogics PDF Java Toolkit

Sample of the Week:

Despite the near ubiquitous use of PDF to exchange documents, there are still rooms… and rooms… and rooms of paper documents in cold storage in offices all over the world. Often times, the first stop on the way to becoming useful again, these documents are scanned to TIFF and stored on massive hard drives. This article is going to be far shorter than my usual Sample of the Week articles because converting these TIFF files to PDF using the Datalogics PDF Java Toolkit is incredibly simple. The developer simply needs to convert a standard Java BufferedImage to a PDFXObjectImage before placement on a PDF page; this also works for any kind of image, not just TIFF. The fun part is figuring out what size page to put it on.

The image portion of an image file really only knows about it’s width and height. To calculate the pixel density, you need to look at the metadata associated with that image. In the Gist below we assume that the images have square pixels so we just use the “HorizontalPixelSize” for my calculation. PDF pages are measured in points (72 per inch) so in order to determine the right size PDF page to add our image to, we need to know the height, width, and pixel density… a little bit of math later and we have our page size.

Knowing the page size, we can now create a new blank PDFPage , add it the document by inserting it in the PDFPageTree and then cover the entire page with the image.

This Gist uses a multi-page TIFF file as the input source but the code can be easily modified to accept multiple separate image files. If you plan on converting other image formats to PDF and you want to retain the same pixel density as the original image, the metadata will be different so that portion of the code will need to change as well.

You’ll also need at least an evaluation version of the Datalogics PDF Java Toolkit to run this code as well as the Java Advanced Imaging ImageIO Tools for reading the TIFF files.

2 thoughts on “Converting TIFF to PDF Using the Datalogics PDF Java Toolkit

    1. Hi Shreesha, we do have a PDF Library with a .NET interface – Adobe PDF Library. Converting HTML to PDF is an interesting idea. We might be able to work with you towards a solution using APDFL. Would you have a few minutes to talk about the problem you are trying to solve? I’ve sent you an email with my contact information.

Leave a Reply

Your email address will not be published. Required fields are marked *