Click here to Skip to main content
Click here to Skip to main content

Tagged as

TIFF and PDF: What’s the Difference and How to Convert Between Them

, 24 Jul 2009 CPOL
TIFF and PDF are the two most popular formats for document imaging. The primary reasons are that they both can store multiple pages in one file and both allow each page to have different sizes and compression. However, knowing the differences will help you choose between the two formats.

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

TIFF and PDF are the two most popular formats for document imaging (documents that come from a scanner). The primary reasons are that they both can store multiple pages in one file and both allow each page to have different sizes and compression.

However, there are differences and knowing them will help you choose between the two formats. Here’s a brief overview of them:

TIFF

A TIFF file is a container of compressed images and metadata. Each individual frame of the TIFF can be compressed with one of a few different compression methods depending on the nature of the image in the frame.

The compression formats available include JPEG, LZW (similar to GIF), Flate (similar to PNG), and a few that are tuned for 1 bpp (black and white) images (Group 3, Group 4, and a Huffman based run length encoding method). There is also the option for no compression if decoding and encoding speed are important. In addition, individual frames can be stored as strips or tiles so that parts of an image can be accessed without requiring the entire page to be decoded.

Because of ambiguity in the original specification, there was a proliferation of dialects, especially with concerns to what is called “Old-Style” JPEG (replaced with “New-style”). The standard Codec that comes with Windows XP and Vista doesn’t even try to read “Old-style” because of the problems in specifying what that exactly is. Support for the various old-style variants is usually only found in third-party toolkits (for example, the DotImage .NET TIFF SDK).

PDF

PDF was originally developed by Adobe as an archival format for documents, but is often used to hold images because it can contain multiple pages. PDF is a well-specified format, and the Acrobat Reader or equivalent is installed on nearly every machine and many mobile devices. Like TIFF, PDFs can contain multiple pages, and each individual page can be compressed based on its content.

Like TIFF, PDF can store an image as JPEG, Deflate (similar to PNG), and Group 4. In addition, it supports two advanced codecs. The first, JPEG 2000, is for photographs and loses much less quality compared to JPEG for the same file size. The second, JBIG2, is tuned for 1-bit black and white images.

Since PDF is designed to contain more than just images, they are ideal for storing the results of images that have had optical character recognition (OCR) performed on them. The recognized text can accurately be placed behind the pixels representing the text. If this is done, the resulting PDF is called a Searchable PDF, and search engines will index them, and some viewers will allow you to select and search for text within them. You can create Searchable PDF with the DotImage .NET OCR and Searchable PDF SDK.

When to Use TIFF over PDF

  1. You don’t OCR the images, or you do, and want to keep the results separate.
  2. Storage size is an important factor.
  3. Everyone who needs to see the image has access to viewing software (if you need to, you can create custom viewers with the DotImage .NET TIFF Viewing SDK).
  4. You need to maintain compatibility with the WANG annotation format.
  5. You have very large pages that need to be accessed in pieces (TIFF supports a tiled mode that allows very fast access to parts of an image – DotImage’s TIFF SDK supports creating and using this style directly)

When to Use PDF over TIFF

  1. You OCR the images and want to keep the results with the image (Create searchable PDF)
  2. Your organization mandates an archival format like PDF/A for compliance purposes.
  3. You want users to be able to view the documents without installing special viewers, and they likely have a PDF viewer, like Acrobat Reader, already.
  4. You annotate the images and want users with Acrobat Reader to be able to see the annotations, so you will store them in the PDF as PDF-compliant annotations (easy to do with DotImage’s .NET PDF SDK)

How to convert between TIFF and PDF

Converting between TIFF and PDF using .NET usually requires a third-party .NET PDF/TIFF SDK, like DotImage. Here’s sample code for going between the two formats:

Converting Multiframe (Multipage) Formats

Converting between multiframe formats in DotImage is simple. All multiframed image encoders inherit from a base class called MultiFramedImageEncoder, which has a Save method. In addition, there is a class called FileSystemImageSource, which can read multiframed formats from files and provides each page as an image to any class that needs them. One of the overloads of MultiFramedImageEncoder.Save() takes any ImageSource as a parameter and saves each page into a Stream in a memory efficient way.

Using these classes, we can write this C# function:

   private void Convert(string inFile, string outFile, MultiFramedImageEncoder encoder)
   {
      using (ImageSource src = new FileSystemImageSource(inFile, true))
      {
         using (Stream s = File.OpenWrite(outFile))
         {
            encoder.Save(s, src, null);
         }
      }
   }

In VB.NET, the function is:

    Private Sub Convert(ByVal inFile As String, ByVal outFile As String, _
                        ByVal encoder As MultiFramedImageEncoder)

        Using src As ImageSource = New FileSystemImageSource(inFile, True)
            Using s As Stream = File.OpenWrite(outFile)
                encoder.Save(s, src, Nothing)
            End Using
        End Using
    End Sub

To convert a TIFF to a PDF, call Convert() like this:

Convert(tiffFileName, pdfFileName, new PdfEncoder());

To convert a PDF to a TIFF, call it like this

Convert(pdfFileName, tiffFileName, new TiffEncoder());

In order to read a PDF, you will need the DotImage PDFReader Add-on SDK, and will need to call this code one time in your application before any PDFs are read:

 RegisteredDecoders.Decoders.Add(new PdfDecoder());

This registers the add-on’s PdfDecoder with the system so that PDFs can be detected and read.

By default, DotImage will pick the best compression method based on the content of the image. However, if you want more control, each encoder class offers many hooks for you to change or refine the compression as the images are saved.

To convert TIFF to PDF, you need DotImage Document Imaging, and to convert PDF to TIFF, you need to add the PDFReader Add-on to DotImage Document Imaging. Both products are available with a runtime-royalty free license for desktop deployments.

Archives

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Lou Franco
Atalasoft, Inc.
United States United States
Lou Franco is the Director of Engineering at Atalasoft, provider of the leading .NET Imaging SDK (DotImage) and the Document Viewer for SharePoint (Vizit).
 
http://atalasoft.com/products/dotimage
http://vizitsp.com

Comments and Discussions

 
Questionthanks for sharing Pinmemberdanny rough7-May-13 18:41 
thanks for sharing this wonderful article with us , i was confused about the differences and the way to convert between two formats , you have done a good job. but your way to convert the images might be somewhat sophisticated , i think it is the era of internet, you can find image converter everywhere on the internet so why we have to waste our time. as for me , i am now clear of the difference but speaking of conversion, i always employ an imaging sdk which can do such conversion for its easyness and quickness, so if you are tired of the complex process , you can have a try , good luck.
http://www.rasteredge.com/how-to/csharp-imaging/pdf-convert-tiff/[^]
QuestionUse Saaspose online converter Pinmemberzarfishan19835-Nov-12 19:52 
GeneralI love this article PinmemberNightJammer8-Sep-09 12:29 
GeneralRe: I love this article PinmemberLou Franco9-Sep-09 4:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411022.1 | Last Updated 24 Jul 2009
Article Copyright 2009 by Lou Franco
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid