Tiff Images
DynamicPDF Core Suite for .NET natively supports Multi-page TIFF documents and includes a method to convert a multipage TIFF document to PDF quickly. The TiffFile class handles multipage TIFFs.
TiffFile
Use the TiffFile when loading TIFF images. It has three overloaded constructors, one taking a file path, another taking a byte array, and a third taking a Stream.
TiffFile(String)
TiffFile(Byte[])
TiffFile(Stream)
Properties
The TiffFile class has two properties, one for obtaining the first image of a multi-page TIFF and another for getting all the images of a multi-page TIFF.
Property | Description |
---|---|
FirstImage | Returns the first image in the TIFF file. |
Images | Returns a collection of images in the TIFF file. |
Methods
The TiffFile class has the following methods.
Method | Description |
---|---|
Close() | Closes the stream associated with this object. |
Equals(Object) | Determines whether the specified Object is equal to the current Object . (Inherited from Object) |
GetDocument() | Creates a Document object that contains the images of the tiff file. |
GetHashCode() | Serves as a hash function for a particular type. (Inherited from Object) |
GetType() | Gets the Type of the current instance. (Inherited from Object) |
IsValid(Byte[]) | Returns a value indicating if the provides file header is valid for a TIFF image. |
IsValid(String) | Returns a value indicating if the provides file extension is valid for a TIFF image. |
ToString() | Returns a String that represents the current Object . (Inherited from Object) |
Accessing Pages from a Multi-page TIFF
To access images from a TIFF, use the TiffFile class's Images property. This property contains a collection (TiffImageDataList) of TiffImageData image objects for each document page. Access the individual images (TiffImageData) by referring to their index value in the TiffImageDataList. Use these individual images in any Image or BackgroundImage constructor.
The following example illustrates obtaining images from a multi-page TIFF.
// get the tiff from the TIFF image.
TiffFile tiffFile = new TiffFile( @"C:\MyMultipageTiff.tif" );
// get the first tiff from the image list collection
// Add the first page as an image.
page1.Elements.Add( new Image( tiffFile.Images[0], 0, 0 ) );
// get the second tiff from the image list collection
// 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
Convert a Tiff to a PDF using a TiffFile instance's GetDocument method. The method returns a Document object that then uses the Document instance's Draw method to output the image(s) as a PDF. Note that the produced PDF contains one page per image. For example, a multi-page tiff with four images would create a four-page PDF.
The following example illustrates converting a TIFF to a PDF.
// 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()
Always call the Close method after the Draw method; internally, the image stream is not closed by default.