|
| 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 libraries. |
| 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 | + |
| 23 | + |
| 24 | +## Solution |
| 25 | + |
| 26 | +To convert a PDF document to a multipage TIFF image, follow the steps below: |
| 27 | + |
| 28 | +1. Use the [PdfFormatProvider]({%slug radpdfprocessing-formats-and-conversion-pdf-pdfformatprovider%}) to import the PDF document. |
| 29 | +2. Iterate through all the pages ([RadFixedPage]({%slug radpdfprocessing-model-radfixedpage%})) of the imported [RadFixedDocument](%slug radpdfprocessing-model-radfixeddocument%). |
| 30 | +3. For each page, create a thumbnail image. |
| 31 | +4. Render each thumbnail image onto a `RenderTargetBitmap`. |
| 32 | +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). |
| 33 | +6. Save the encoded TIFF image to a file. |
| 34 | + |
| 35 | +Here is the code snippet demonstrating this process: |
| 36 | + |
| 37 | +```csharp |
| 38 | +[STAThread] |
| 39 | +private static void Main(string[] args) |
| 40 | +{ |
| 41 | + string inputFilePath = @"path_to_your_pdf_document.pdf"; |
| 42 | + PdfFormatProvider pdfProcessingProvider = new PdfFormatProvider(); |
| 43 | + RadFixedDocument document = pdfProcessingProvider.Import(File.ReadAllBytes(inputFilePath)); |
| 44 | + ThumbnailFactory factory = new ThumbnailFactory(); |
| 45 | + BitmapEncoder encoder = new TiffBitmapEncoder(); |
| 46 | + string exportedFileName = "Exported.tiff"; |
| 47 | + using (FileStream fileStream = new FileStream(exportedFileName, FileMode.Create)) |
| 48 | + { |
| 49 | + foreach (RadFixedPage page in document.Pages) |
| 50 | + { |
| 51 | + ImageSource imageSource = factory.CreateThumbnail(page, page.Size); |
| 52 | + System.Windows.Controls.Image image = new System.Windows.Controls.Image(); |
| 53 | + image.Source = imageSource; |
| 54 | + Grid container = new Grid(); |
| 55 | + container.Background = Brushes.White; |
| 56 | + container.Children.Add(image); |
| 57 | + container.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); |
| 58 | + container.Arrange(new Rect(new Point(0, 0), container.DesiredSize)); |
| 59 | + |
| 60 | + RenderTargetBitmap bitmap = new RenderTargetBitmap((int)PageLayoutHelper.GetActualWidth(page), |
| 61 | + (int)PageLayoutHelper.GetActualHeight(page), 96, 96, PixelFormats.Pbgra32); |
| 62 | + bitmap.Render(container); |
| 63 | + |
| 64 | + encoder.Frames.Add(BitmapFrame.Create(bitmap)); |
| 65 | + } |
| 66 | + encoder.Save(fileStream); |
| 67 | + } |
| 68 | + Process.Start(new ProcessStartInfo() { FileName = exportedFileName, UseShellExecute = true }); |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +## Required Assemblies |
| 73 | + |
| 74 | +* Telerik.Windows.Controls.FixedDocumentViewers.dll |
| 75 | +* Telerik.Windows.Documents.Core.dll |
| 76 | +* Telerik.Windows.Documents.Fixed.dll |
| 77 | +* WindowsBase.dll |
| 78 | +* PresentationCore.dll |
| 79 | + |
| 80 | +## Notes |
| 81 | + |
| 82 | +- Ensure you have added references to the necessary Telerik Document Processing and WPF libraries in your project. |
| 83 | +- Adjust the `inputFilePath` variable to point to your PDF document. |
| 84 | +- 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. |
| 85 | + |
| 86 | +## See Also |
| 87 | + |
| 88 | +- [RadPdfProcessing Overview]({%slug radpdfprocessing-overview%}) |
| 89 | +- [Export RadFixedPage to TIFF Image]({%slug export-radfixedpage-to-image%}) |
| 90 | +- [TiffBitmapEncoder Class Documentation](https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.tiffbitmapencoder) |
| 91 | +- [Using SkiaImageFormatProvider]({%slug radpdfprocessing-formats-and-conversion-image-using-skiaimageformatprovider%}) |
| 92 | +- [Converting Multi-page TIFF Images to PDF]({%slug convert-tiff-to-pdf-radpdfprocessing%}) |
0 commit comments