Tiff Images

DynamicPDF Core Suite for .NET natively supports Multi-page TIFF documents and includes a method to quickly convert a multi-page TIFF document to PDF. Multi-page TIFFs are handled using the TiffFile class.

Accessing Pages from a Multi-page TIFF

TiffFile objects contain a collection of TiffImageData objects for each page in a document. These TiffImageData objects are accessed by index and used in any Image or BackgroundImage constructor.

// Create a TiffFile object from the TIFF image.
TiffFile tiffFile = new TiffFile( @"C:\MyMultipageTiff.tif" );
// Add the first page as an image.
page1.Elements.Add( new Image( tiffFile.Images[0], 0, 0 ) );
// Add the second page to the page as a background image.
page2.Elements.Add( new BackgroundImage( tiffFile.Images[1] ) );        
' Create a TiffFile object from the TIFF image.
Dim MyTiffFile As TiffFile = New TiffFile( "C:\MyMultipageTiff.tif" )
' Add the first page as an image.
MyPage1.Elements.Add( New Image( MyTiffFile.Images(0), 0, 0 ) )
' Add the second page to the page as a background image.
MyPage2.Elements.Add( New BackgroundImage( MyTiffFile.Images(1) ) )

Converting a Tiff to PDF

A Tiff can be converted to PDF with just three lines of code using the TiffFile objects GetDocument method:

// Create a TiffFile object from the TIFF image.
TiffFile tiffFile = new TiffFile( @"C:\MyMultipageTiff.tif" );
// Create a document object from the file.
Document document = tiffFile.GetDocument();
// Output the document to a file.
document.Draw(pdfFilePath);
tiffFile.Close();        
' Create a TiffFile object from the TIFF image.
Dim MyTiffFile As TiffFile = New TiffFile( "C:\MyMultipageTiff.tif" )
' Create a document object from the file.
Dim MyDocument As Document = MyTiffFile.GetDocument()
' Output the document to a file.
MyDocument.Draw(pdfFilePath)
MyTiffFile.Close() 

Notes:

1. For handling TIFF files, always use TiffFile object class.
2. When using TiffFile object, always call the Close() method after draw method because internally the image stream will not be closed.

In this topic