|
| 1 | +--- |
| 2 | +title: Converting PDF to TIFF with RadPdfProcessing in .NET Standard |
| 3 | +description: This article demonstrates how to convert PDF documents to TIFF images in .NET Standard applications using RadPdfProcessing. |
| 4 | +type: how-to |
| 5 | +page_title: How to Convert PDF Documents to TIFF Images Using RadPdfProcessing in .NET Standard |
| 6 | +slug: convert-pdf-to-tiff-radpdfprocessing-net-core |
| 7 | +tags: radpdfprocessing, document, processing, pdf, tiff, conversion, net, standard |
| 8 | +res_type: kb |
| 9 | +ticketid: 1682497 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +| Version | Product | Author | |
| 15 | +| ---- | ---- | ---- | |
| 16 | +| 2025.1.205| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +Learn how to convert PDF documents to TIFF format in .NET Standard. |
| 21 | + |
| 22 | +## Solution |
| 23 | + |
| 24 | +To convert PDF documents to TIFF images in .NET Standard, follow these steps: |
| 25 | + |
| 26 | +1. Use the [SkiaImageFormatProvider]({%slug radpdfprocessing-formats-and-conversion-image-using-skiaimageformatprovider%}) to export the PDF pages to images. |
| 27 | +2. Utilize the [System.Drawing.Common](https://www.nuget.org/packages/System.Drawing.Common/) library to assemble these images into a multi-page TIFF file. |
| 28 | + |
| 29 | +Here's an example code snippet demonstrating the process: |
| 30 | + |
| 31 | +```csharp |
| 32 | +using System.Diagnostics; |
| 33 | +using System.Drawing; |
| 34 | +using System.Drawing.Imaging; |
| 35 | +using Telerik.Documents.Fixed.FormatProviders.Image.Skia; |
| 36 | +using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf; |
| 37 | +using Telerik.Windows.Documents.Fixed.Model; |
| 38 | +using System.IO; |
| 39 | + |
| 40 | +namespace PdfToTIFFNetCore |
| 41 | +{ |
| 42 | + internal class Program |
| 43 | + { |
| 44 | + [STAThread] |
| 45 | + static void Main(string[] args) |
| 46 | + { |
| 47 | + PdfFormatProvider pdfFormatProvider = new PdfFormatProvider(); |
| 48 | + RadFixedDocument fixedDocument = pdfFormatProvider.Import(File.ReadAllBytes("your-pdf-file.pdf"), TimeSpan.FromSeconds(10)); |
| 49 | + SkiaImageFormatProvider imageProvider = new SkiaImageFormatProvider(); |
| 50 | + string exportedFileName = "Exported.tiff"; |
| 51 | + using (FileStream fileStream = new FileStream(exportedFileName, FileMode.Create)) |
| 52 | + { |
| 53 | + System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.SaveFlag; |
| 54 | + ImageCodecInfo codecInfo = GetEncoderInfo("image/tiff"); |
| 55 | + EncoderParameters encoderParams = new EncoderParameters(1); |
| 56 | + encoderParams.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame); |
| 57 | + |
| 58 | + Bitmap firstImage = null; |
| 59 | + bool firstFrame = true; |
| 60 | + |
| 61 | + foreach (RadFixedPage page in fixedDocument.Pages) |
| 62 | + { |
| 63 | + byte[] resultImage = imageProvider.Export(page, TimeSpan.FromSeconds(10)); |
| 64 | + using (MemoryStream ms = new MemoryStream(resultImage)) |
| 65 | + { |
| 66 | + using (Bitmap bitmap = new Bitmap(ms)) |
| 67 | + { |
| 68 | + if (firstFrame) |
| 69 | + { |
| 70 | + firstImage = new Bitmap(bitmap); |
| 71 | + firstImage.Save(fileStream, codecInfo, encoderParams); |
| 72 | + firstFrame = false; |
| 73 | + } |
| 74 | + else |
| 75 | + { |
| 76 | + encoderParams.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage); |
| 77 | + firstImage.SaveAdd(bitmap, encoderParams); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + encoderParams.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush); |
| 84 | + firstImage.SaveAdd(encoderParams); |
| 85 | + } |
| 86 | + |
| 87 | + Process.Start(new ProcessStartInfo() { FileName = exportedFileName, UseShellExecute = true }); |
| 88 | + } |
| 89 | + |
| 90 | + private static ImageCodecInfo GetEncoderInfo(string mimeType) |
| 91 | + { |
| 92 | + ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); |
| 93 | + foreach (ImageCodecInfo codec in codecs) |
| 94 | + { |
| 95 | + if (codec.MimeType == mimeType) |
| 96 | + { |
| 97 | + return codec; |
| 98 | + } |
| 99 | + } |
| 100 | + return null; |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +Replace `"your-pdf-file.pdf"` with the path to your PDF file. This code will create a TIFF file named `Exported.tiff` containing all the pages from the PDF document. |
| 107 | + |
| 108 | +## See Also |
| 109 | + |
| 110 | +- [Converting a PDF Document to a Multipage TIFF Image]({%slug convert-pdf-to-multipage-tiff-radpdfprocessing%}) |
| 111 | + |
0 commit comments