article

How to Convert PDF Pages to TIFF Image inside .NET Applications

Email
Submitted on: 6/22/2016 7:02:01 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 3451
 
     This technical tip shows how to convert PDF pages to TIFF image inside .NET Applications. The TiffDevice class allows you to convert PDF pages to TIFF images. This class provides a method named Process which allows you to convert all the pages in a PDF file to a single TIFF image. To convert a particular page in a PDF file to a TIFF image, use an overloaded version of the Process(..) method which takes a page number as an argument for conversion.

 
				This technical tip shows how to convert PDF pages to TIFF image inside .NET Applications. The TiffDevice class allows you to convert PDF pages to TIFF images. This class provides a method named Process which allows you to convert all the pages in a PDF file to a single TIFF image. To convert a particular page in a PDF file to a TIFF image, use an overloaded version of the Process(..) method which takes a page number as an argument for conversion. To convert all pages in a PDF file to a single TIFF image:
•	Create an object of the Document class.
•	Call the Process method to convert the document.
•	To set the output file's properties, use the TiffSettings class.
The following code snippet shows how to convert all the PDF pages to a single TIFF image.
//[C# Code Sample]
 
// Open document
Document pdfDocument = new Document("input.pdf");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.None;
tiffSettings.Depth = ColorDepth.Default;
tiffSettings.Shape = ShapeType.Landscape;
tiffSettings.SkipBlankPages = false;
// Create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
// Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, "output.tif");
//[VB.NET Code Sample]
 
'Open document
Dim pdfDocument As New Document("input.pdf")
'Create Resolution object
Dim resolution As New Resolution(300)
'Create TiffSettings object
Dim tiffSettings As New TiffSettings()
tiffSettings.Compression = CompressionType.None
tiffSettings.Depth = ColorDepth.Default
tiffSettings.Shape = ShapeType.Landscape
tiffSettings.SkipBlankPages = False
'Create TIFF device
Dim tiffDevice As New TiffDevice(resolution, tiffSettings)
'Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, "output.tif")
//Convert One Page to TIFF Image
//[C# Code Sample]
 
// Open document
Document pdfDocument = new Document("input.pdf");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.None;
tiffSettings.Depth = ColorDepth.Default;
tiffSettings.Shape = ShapeType.Landscape;
tiffSettings.SkipBlankPages = false;
// Create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
// Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, 1, 1, "output.tif");
//[VB.NET Code Sample]
 
'Open document
Dim pdfDocument As New Document("input.pdf")
'Create Resolution object
Dim resolution As New Resolution(300)
'Create TiffSettings object
Dim tiffSettings As New TiffSettings()
tiffSettings.Compression = CompressionType.None
tiffSettings.Depth = ColorDepth.Default
tiffSettings.Shape = ShapeType.Landscape
tiffSettings.SkipBlankPages = False
'Create TIFF device
Dim tiffDevice As New TiffDevice(resolution, tiffSettings)
'Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, 1, 1, "output.tif")
//Use Bradley algorithm during conversion
Aspose.Pdf for .NET has been supporting the feature to convert PDF to TIF using LZW compression and then with the use of AForge, Binarization can be applied. However one of the customers requested that for some images, they need to get the Threshold using Otsu, so they also would like to use Bradley.
//[C# Code Sample]
 
string outputImageFile = @"c:\resultant.tif";
string outputBinImageFile = @"c:\37116-bin.tif";
//open document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"c:\input.pdf");
//create Resolution object
Resolution resolution = new Resolution(300);
//create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.LZW;
tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp;
//create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
//convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, outputImageFile);
using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open))
{
using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create))
{
 tiffDevice.BinarizeBradley(inStream, outStream, 0.1);
}
}
//[VB.NET Code Sample]
 
Dim outputImageFile As String = "c:\resultant.tif"
Dim outputBinImageFile As String = "c:\37116-bin.tif"
'open document
Dim pdfDocument As Aspose.Pdf.Document = New Aspose.Pdf.Document("c:\input.pdf")
'create Resolution object
Dim resolution As Aspose.Pdf.Devices.Resolution = New Aspose.Pdf.Devices.Resolution(300)
'create TiffSettings object
Dim tiffSettings As TiffSettings = New TiffSettings()
tiffSettings.Compression = CompressionType.LZW
tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp
'create TIFF device
Dim tiffDevice As TiffDevice = New TiffDevice(resolution, tiffSettings)
'convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, outputImageFile)
Using inStream As FileStream = New FileStream(outputImageFile, FileMode.Open)
Using outStream As FileStream = New FileStream(outputBinImageFile, FileMode.Create)
tiffDevice.BinarizeBradley(inStream, outStream, 0.1)
End Using
End Using

More about Aspose.Pdf for .NET


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.