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.

Share this post with your friends

4 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.

  1. I have been searching to read the API documentation which converts from HTML to PDF using the .NET framework but with not so much of success. Can you please lead me to there or I would be happy to talk to any one of you to explain the problem I have. Please be noted, I want to create the PDF’s using the batch processing method (programmatically).

Leave a Comment

Your email address will not be published.

Get instant access to the latest PDF news, tips and tricks!

Do you want monthly updates on the latest document technology trends?

By submitting the form, you agree to receive marketing emails from Datalogics. You may unsubscribe at any time. 

Like what you're reading?

Get Datalogics blogs sent right to your inbox!

By submitting the form, you agree to receive marketing emails from Datalogics. You may unsubscribe at any time.