Skip to content

Commit 94e30fc

Browse files
author
KB Bot
committed
Added new kb article convert-pdf-to-multipage-tiff-radpdfprocessing
1 parent f754083 commit 94e30fc

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Converting a PDF Document to a Multipage TIFF Image
3+
description: Learn how to transform PDF documents into multipage TIFF files using RadPdfProcessing from the Document Processing library.
4+
type: how-to
5+
page_title: How to Convert PDF Documents to Multipage TIFF with RadPdfProcessing
6+
slug: convert-pdf-to-multipage-tiff-radpdfprocessing
7+
tags: pdfprocessing, document, processing, pdf, tiff, image conversion, multipage
8+
res_type: kb
9+
ticketid: 1660512
10+
---
11+
12+
## Environment
13+
14+
| Version | Product | Author |
15+
| --- | --- | ---- |
16+
| 2024.2.426| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
17+
18+
## Description
19+
20+
When working with PDF documents, a common task might be to convert the PDF pages into multipage TIFF images. This scenario arises due to the need for image-based representations of document pages, often for archival or compatibility reasons with certain systems that prefer image formats. Converting a PDF document to a multipage TIFF file can be challenging, as this functionality is not directly supported by many graphic applications, including Adobe. This KB article demonstrates how to convert PDF documents to multipage TIFF images using RadPdfProcessing.
21+
22+
## Solution
23+
24+
To convert a PDF document to a multipage TIFF image, follow the steps below:
25+
26+
1. Use the `PdfFormatProvider` to import the PDF document.
27+
2. Iterate through all the pages of the imported document.
28+
3. For each page, create a thumbnail image.
29+
4. Render each thumbnail image onto a `RenderTargetBitmap`.
30+
5. Add each rendered bitmap as a frame to a `TiffBitmapEncoder`.
31+
6. Save the encoded TIFF image to a file.
32+
33+
Here is the code snippet demonstrating this process:
34+
35+
```csharp
36+
[STAThread]
37+
private static void Main(string[] args)
38+
{
39+
string inputFilePath = @"path_to_your_pdf_document.pdf";
40+
PdfFormatProvider pdfProcessingProvider = new PdfFormatProvider();
41+
RadFixedDocument document = pdfProcessingProvider.Import(File.ReadAllBytes(inputFilePath));
42+
ThumbnailFactory factory = new ThumbnailFactory();
43+
BitmapEncoder encoder = new TiffBitmapEncoder();
44+
string exportedFileName = "Exported.tiff";
45+
using (FileStream fileStream = new FileStream(exportedFileName, FileMode.Create))
46+
{
47+
foreach (RadFixedPage page in document.Pages)
48+
{
49+
ImageSource imageSource = factory.CreateThumbnail(page, page.Size);
50+
System.Windows.Controls.Image image = new System.Windows.Controls.Image();
51+
image.Source = imageSource;
52+
Grid container = new Grid();
53+
container.Background = Brushes.White;
54+
container.Children.Add(image);
55+
container.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
56+
container.Arrange(new Rect(new Point(0, 0), container.DesiredSize));
57+
58+
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)PageLayoutHelper.GetActualWidth(page),
59+
(int)PageLayoutHelper.GetActualHeight(page), 96, 96, PixelFormats.Pbgra32);
60+
bitmap.Render(container);
61+
62+
encoder.Frames.Add(BitmapFrame.Create(bitmap));
63+
}
64+
encoder.Save(fileStream);
65+
}
66+
Process.Start(new ProcessStartInfo() { FileName = exportedFileName, UseShellExecute = true });
67+
}
68+
```
69+
## Notes
70+
71+
- Ensure you have added references to the necessary Telerik Document Processing and WPF libraries in your project.
72+
- Adjust the `inputFilePath` variable to point to your PDF document.
73+
- The generated TIFF file will be saved with the name "Exported.tiff" in the project's directory. You can modify the `exportedFileName` variable to change the output file's name and location.
74+
75+
## See Also
76+
77+
- [RadPdfProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview)
78+
- [Export RadFixedPage to Image KB Article](https://docs.telerik.com/devtools/document-processing/knowledge-base/export-radfixedpage-to-image)
79+
- [TiffBitmapEncoder Class Documentation](https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.tiffbitmapencoder)

0 commit comments

Comments
 (0)