Posted By

sherazam on 06/22/16


Tagged

pages image page pdf Net to a all api convert tiff of first one


Versions (?)

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


 / Published in: C#
 

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.

  1. //The following code snippet shows how to convert all the PDF pages to a single TIFF image.
  2.  
  3. //[C# Code Sample]
  4.  
  5.  
  6. // Open document
  7. Document pdfDocument = new Document("input.pdf");
  8.  
  9. // Create Resolution object
  10. Resolution resolution = new Resolution(300);
  11.  
  12. // Create TiffSettings object
  13. TiffSettings tiffSettings = new TiffSettings();
  14. tiffSettings.Compression = CompressionType.None;
  15. tiffSettings.Depth = ColorDepth.Default;
  16. tiffSettings.Shape = ShapeType.Landscape;
  17. tiffSettings.SkipBlankPages = false;
  18.  
  19. // Create TIFF device
  20. TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
  21.  
  22. // Convert a particular page and save the image to stream
  23. tiffDevice.Process(pdfDocument, "output.tif");
  24.  
  25. //[VB.NET Code Sample]
  26.  
  27.  
  28. 'Open document
  29. Dim pdfDocument As New Document("input.pdf")
  30.  
  31. 'Create Resolution object
  32. Dim resolution As New Resolution(300)
  33.  
  34. 'Create TiffSettings object
  35. Dim tiffSettings As New TiffSettings()
  36. tiffSettings.Compression = CompressionType.None
  37. tiffSettings.Depth = ColorDepth.Default
  38. tiffSettings.Shape = ShapeType.Landscape
  39. tiffSettings.SkipBlankPages = False
  40.  
  41. 'Create TIFF device
  42. Dim tiffDevice As New TiffDevice(resolution, tiffSettings)
  43.  
  44. 'Convert a particular page and save the image to stream
  45. tiffDevice.Process(pdfDocument, "output.tif")
  46.  
  47.  
  48. //Convert One Page to TIFF Image
  49.  
  50. //[C# Code Sample]
  51.  
  52.  
  53. // Open document
  54. Document pdfDocument = new Document("input.pdf");
  55.  
  56. // Create Resolution object
  57. Resolution resolution = new Resolution(300);
  58.  
  59. // Create TiffSettings object
  60. TiffSettings tiffSettings = new TiffSettings();
  61. tiffSettings.Compression = CompressionType.None;
  62. tiffSettings.Depth = ColorDepth.Default;
  63. tiffSettings.Shape = ShapeType.Landscape;
  64. tiffSettings.SkipBlankPages = false;
  65.  
  66. // Create TIFF device
  67. TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
  68.  
  69.  
  70. // Convert a particular page and save the image to stream
  71. tiffDevice.Process(pdfDocument, 1, 1, "output.tif");
  72.  
  73.  
  74. //[VB.NET Code Sample]
  75.  
  76.  
  77. 'Open document
  78. Dim pdfDocument As New Document("input.pdf")
  79.  
  80. 'Create Resolution object
  81. Dim resolution As New Resolution(300)
  82.  
  83. 'Create TiffSettings object
  84. Dim tiffSettings As New TiffSettings()
  85. tiffSettings.Compression = CompressionType.None
  86. tiffSettings.Depth = ColorDepth.Default
  87. tiffSettings.Shape = ShapeType.Landscape
  88. tiffSettings.SkipBlankPages = False
  89.  
  90. 'Create TIFF device
  91. Dim tiffDevice As New TiffDevice(resolution, tiffSettings)
  92.  
  93. 'Convert a particular page and save the image to stream
  94. tiffDevice.Process(pdfDocument, 1, 1, "output.tif")
  95.  
  96. //Use Bradley algorithm during conversion
  97.  
  98. //[C# Code Sample]
  99.  
  100.  
  101. string outputImageFile = @"c:\resultant.tif";
  102. string outputBinImageFile = @"c:\37116-bin.tif";
  103. //open document
  104. Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"c:\input.pdf");
  105. //create Resolution object
  106. Resolution resolution = new Resolution(300);
  107. //create TiffSettings object
  108. TiffSettings tiffSettings = new TiffSettings();
  109. tiffSettings.Compression = CompressionType.LZW;
  110. tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp;
  111. //create TIFF device
  112. TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
  113. //convert a particular page and save the image to stream
  114. tiffDevice.Process(pdfDocument, outputImageFile);
  115.  
  116. using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open))
  117. {
  118. using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create))
  119. {
  120. tiffDevice.BinarizeBradley(inStream, outStream, 0.1);
  121. }
  122. }
  123.  
  124. //[VB.NET Code Sample]
  125.  
  126.  
  127. Dim outputImageFile As String = "c:\resultant.tif"
  128. Dim outputBinImageFile As String = "c:\37116-bin.tif"
  129. 'open document
  130. Dim pdfDocument As Aspose.Pdf.Document = New Aspose.Pdf.Document("c:\input.pdf")
  131. 'create Resolution object
  132. Dim resolution As Aspose.Pdf.Devices.Resolution = New Aspose.Pdf.Devices.Resolution(300)
  133. 'create TiffSettings object
  134. Dim tiffSettings As TiffSettings = New TiffSettings()
  135. tiffSettings.Compression = CompressionType.LZW
  136. tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp
  137. 'create TIFF device
  138. Dim tiffDevice As TiffDevice = New TiffDevice(resolution, tiffSettings)
  139. 'convert a particular page and save the image to stream
  140. tiffDevice.Process(pdfDocument, outputImageFile)
  141.  
  142. Using inStream As FileStream = New FileStream(outputImageFile, FileMode.Open)
  143.  
  144. Using outStream As FileStream = New FileStream(outputBinImageFile, FileMode.Create)
  145. tiffDevice.BinarizeBradley(inStream, outStream, 0.1)
  146. End Using
  147. End Using

Report this snippet  

You need to login to post a comment.