Skip to content

Commit 03c19da

Browse files
author
KB Bot
committed
Added new kb article convert-pdf-to-tiff-radpdfprocessing-net-core
1 parent 6765a24 commit 03c19da

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
title: Converting PDF to TIFF with RadPdfProcessing in .NET Core Applications
3+
description: This article demonstrates how to convert PDF documents to TIFF images in .NET Core applications using RadPdfProcessing.
4+
type: how-to
5+
page_title: How to Convert PDF Documents to TIFF Images Using RadPdfProcessing in .NET Core
6+
slug: convert-pdf-to-tiff-radpdfprocessing-net-core
7+
tags: radpdfprocessing, document processing, pdf, tiff, conversion, .net core, asp.net core
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+
I need to convert PDFs to TIFFs in a .NET 8 ASP.NET Core application. The existing solutions seem to target the .NET Framework, causing compatibility issues. How can I achieve this conversion using RadPdfProcessing in my application?
21+
22+
This knowledge base article also answers the following questions:
23+
- How do I convert PDF documents to TIFF format in a .NET Core application?
24+
- What is the process for exporting PDF pages as images in .NET Core?
25+
- Can I generate a multipage TIFF image from a PDF document using RadPdfProcessing in ASP.NET Core?
26+
27+
## Solution
28+
29+
To convert PDF documents to TIFF images in a .NET Core application, follow these steps:
30+
31+
1. Use the `SkiaImageFormatProvider` to export the PDF pages to images.
32+
2. Utilize the `System.Drawing.Common` library to assemble these images into a multipage TIFF file.
33+
34+
Here's an example code snippet demonstrating the process:
35+
36+
```csharp
37+
using System.Diagnostics;
38+
using System.Drawing;
39+
using System.Drawing.Imaging;
40+
using Telerik.Documents.Fixed.FormatProviders.Image.Skia;
41+
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
42+
using Telerik.Windows.Documents.Fixed.Model;
43+
using System.IO;
44+
45+
namespace PdfToTIFFNetCore
46+
{
47+
internal class Program
48+
{
49+
[STAThread]
50+
static void Main(string[] args)
51+
{
52+
PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
53+
RadFixedDocument fixedDocument = pdfFormatProvider.Import(File.ReadAllBytes("your-pdf-file.pdf"), TimeSpan.FromSeconds(10));
54+
SkiaImageFormatProvider imageProvider = new SkiaImageFormatProvider();
55+
string exportedFileName = "Exported.tiff";
56+
using (FileStream fileStream = new FileStream(exportedFileName, FileMode.Create))
57+
{
58+
System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.SaveFlag;
59+
ImageCodecInfo codecInfo = GetEncoderInfo("image/tiff");
60+
EncoderParameters encoderParams = new EncoderParameters(1);
61+
encoderParams.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);
62+
63+
Bitmap firstImage = null;
64+
bool firstFrame = true;
65+
66+
foreach (RadFixedPage page in fixedDocument.Pages)
67+
{
68+
byte[] resultImage = imageProvider.Export(page, TimeSpan.FromSeconds(10));
69+
using (MemoryStream ms = new MemoryStream(resultImage))
70+
{
71+
using (Bitmap bitmap = new Bitmap(ms))
72+
{
73+
if (firstFrame)
74+
{
75+
firstImage = new Bitmap(bitmap);
76+
firstImage.Save(fileStream, codecInfo, encoderParams);
77+
firstFrame = false;
78+
}
79+
else
80+
{
81+
encoderParams.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage);
82+
firstImage.SaveAdd(bitmap, encoderParams);
83+
}
84+
}
85+
}
86+
}
87+
88+
encoderParams.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
89+
firstImage.SaveAdd(encoderParams);
90+
}
91+
92+
Process.Start(new ProcessStartInfo() { FileName = exportedFileName, UseShellExecute = true });
93+
}
94+
95+
private static ImageCodecInfo GetEncoderInfo(string mimeType)
96+
{
97+
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
98+
foreach (ImageCodecInfo codec in codecs)
99+
{
100+
if (codec.MimeType == mimeType)
101+
{
102+
return codec;
103+
}
104+
}
105+
return null;
106+
}
107+
}
108+
}
109+
```
110+
111+
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.
112+
113+
## See Also
114+
115+
- [RadPdfProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview)
116+
- [Using Image Format Provider](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/formats-and-conversion/convert-to-image/using-image-format-provider)
117+
- [PdfProcessing: Add support for converting a PDF document to a multipage TIFF image](https://feedback.telerik.com/document-processing/1660559-pdfprocessing-add-support-for-converting-a-pdf-document-to-a-multipage-tiff-image)
118+
119+
---

0 commit comments

Comments
 (0)