Skip to content

Added new kb article convert-pdf-to-multipage-tiff-radpdfprocessing #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions knowledge-base/convert-pdf-to-multipage-tiff-radpdfprocessing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: Converting a PDF Document to a Multipage TIFF Image
description: Learn how to transform PDF documents into multipage TIFF files using RadPdfProcessing from the Document Processing libraries.
type: how-to
page_title: How to Convert PDF Documents to Multipage TIFF with RadPdfProcessing
slug: convert-pdf-to-multipage-tiff-radpdfprocessing
tags: pdfprocessing, document, processing, pdf, tiff, image, conversion, multipage
res_type: kb
ticketid: 1660512
---

## Environment

| Version | Product | Author |
| --- | --- | ---- |
| 2024.2.426| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|

## Description

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.

![Convert PDF to Multipage TIFF](images/pdf-to-multiple-page-tiff.gif)

## Solution

To convert a PDF document to a multipage TIFF image, follow the steps below:

1. Use the [PdfFormatProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-pdfformatprovider%}) to import the PDF document.
2. Iterate through all the pages ([RadFixedPage]({%slug radpdfprocessing-model-radfixedpage%})) of the imported [RadFixedDocument](%slug radpdfprocessing-model-radfixeddocument%).
3. For each page, create a thumbnail image.
4. Render each thumbnail image onto a `RenderTargetBitmap`.
5. Add each rendered bitmap as a frame to a [TiffBitmapEncoder](https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.tiffbitmapencoder?view=windowsdesktop-8.0).
6. Save the encoded TIFF image to a file.

Here is the code snippet demonstrating this process:

```csharp
[STAThread]
private static void Main(string[] args)
{
string inputFilePath = @"path_to_your_pdf_document.pdf";
PdfFormatProvider pdfProcessingProvider = new PdfFormatProvider();
RadFixedDocument document = pdfProcessingProvider.Import(File.ReadAllBytes(inputFilePath));
ThumbnailFactory factory = new ThumbnailFactory();
BitmapEncoder encoder = new TiffBitmapEncoder();
string exportedFileName = "Exported.tiff";
using (FileStream fileStream = new FileStream(exportedFileName, FileMode.Create))
{
foreach (RadFixedPage page in document.Pages)
{
ImageSource imageSource = factory.CreateThumbnail(page, page.Size);
System.Windows.Controls.Image image = new System.Windows.Controls.Image();
image.Source = imageSource;
Grid container = new Grid();
container.Background = Brushes.White;
container.Children.Add(image);
container.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
container.Arrange(new Rect(new Point(0, 0), container.DesiredSize));

RenderTargetBitmap bitmap = new RenderTargetBitmap((int)PageLayoutHelper.GetActualWidth(page),
(int)PageLayoutHelper.GetActualHeight(page), 96, 96, PixelFormats.Pbgra32);
bitmap.Render(container);

encoder.Frames.Add(BitmapFrame.Create(bitmap));
}
encoder.Save(fileStream);
}
Process.Start(new ProcessStartInfo() { FileName = exportedFileName, UseShellExecute = true });
}
```

## Required Assemblies

* Telerik.Windows.Controls.FixedDocumentViewers.dll
* Telerik.Windows.Documents.Core.dll
* Telerik.Windows.Documents.Fixed.dll
* WindowsBase.dll
* PresentationCore.dll

## Notes

- Ensure you have added references to the necessary Telerik Document Processing and WPF libraries in your project.
- Adjust the `inputFilePath` variable to point to your PDF document.
- 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.

## See Also

- [RadPdfProcessing Overview]({%slug radpdfprocessing-overview%})
- [Export RadFixedPage to TIFF Image]({%slug export-radfixedpage-to-image%})
- [TiffBitmapEncoder Class Documentation](https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.tiffbitmapencoder)
- [Using SkiaImageFormatProvider]({%slug radpdfprocessing-formats-and-conversion-image-using-skiaimageformatprovider%})
- [Converting Multi-page TIFF Images to PDF]({%slug convert-tiff-to-pdf-radpdfprocessing%})
1 change: 1 addition & 0 deletions knowledge-base/convert-tiff-to-pdf-radpdfprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ This approach ensures the TIFF images are converted to PDF format without any pa
- [RadPdfProcessing Documentation]({%slug radpdfprocessing-overview%})
- [How to Generate a PDF Document from Images with FixedContentEditor]({%slug pdf-from-images-with-fixedcontenteditor%})
- [How to Generate a PDF Document from Images with RadFixedDocumentEditor]({%slug pdf-from-images-with-radfixeddocumenteditor%})
- [Converting a PDF Document to a Multipage TIFF Image]({%slug convert-pdf-to-multipage-tiff-radpdfprocessing%})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ The __SkiaImageFormatProvider__ exposes the following settings:
* [Converting XLSX Content to DOCX Document]({%slug convert-excel-content-to-word-document%})
* [Export Worksheet to image]({%slug spreadprocessing-export-worksheet-to-image-netstandard%})
* [Cropping PDF Pages and Saving as Images Using RadPdfProcessing]({%slug crop-save-pdf-pages-as-images-radpdfprocessing%})
* [Converting a PDF Document to a Multipage TIFF Image]({%slug convert-pdf-to-multipage-tiff-radpdfprocessing%})
* [Converting Multi-page TIFF Images to PDF]({%slug convert-tiff-to-pdf-radpdfprocessing%})