Turn PDF Pages Into Images With PdfProcessing

Check out the new functionality of Telerik PdfProcessing to convert PDF pages to images.


This content originally appeared on Telerik Blogs and was authored by Tanya Dimitrova

Check out the new functionality of Telerik PdfProcessing to convert PDF pages to images.

Many of you requested us to provide you with the ability to export your documents or parts of them to images in .NET Standard/.NET Core applications. As we are always listening to your feedback, during the last release we worked hard to provide you with this functionality and I will present it in this blog post.

To make it possible for all platforms using the .NET Standard version of PdfProcessing to create images, the library uses a third-party tool for image generation—SkiaSharp. Multiple image formats are supported, and you can also choose whether to perform the exporting operation synchronously or asynchronously.

Let’s take a closer look at the API related to the new functionality. The entry point making all the magic is the SkiaImageFormatProvider class. If you are already using PdfProcessing, you should be familiar with the format providers and how they work. For all the rest, in short, the format providers expose Import and Export methods that enable you to parse a document into the internal model of the library or save the information from this model into a document file, respectively.

Let’s Create an Example

To better demonstrate the functionality and its usage, I will guide you step by step on creating an application that opens an existing PDF document and converts its pages into images.

First things first—I will create a console application and add the dependencies we need to use the PdfProcessing library. For more convenience, I will directly go with the Telerik.Documents.Fixed.FormatProviders.Image.Skia NuGet package that will download all of its dependencies automatically:

Telerik.Documents.Fixed.FormatProviders.Image.Skia NuGet package in Visual Studio NuGet Manager

In case you prefer adding references to the .dll files, here is the list of required assemblies:

  • Telerik.Documents.Core
  • Telerik.Documents.Fixed
  • Telerik.Zip
  • Telerik.Documents.Fixed.FormatProviders.Image.Skia

As I mentioned earlier, the image exporting functionality depends on SkiaSharp, thus you will need to add dependencies to its binaries as well:

  • The SkiaSharp NuGet package
  • The SkiaSharp.NativeAssets.* NuGet package. This package may differ according to the used platform. There are versions for Windows, MacOS, Linux, WebAssembly, Android, iOS and others.

Once we are ready with the setup, we can continue to add some logic to our application. The first step we need to implement is to read the PDF document we already have:

byte[] fileBytes = File.ReadAllBytes("SampleDocument.pdf");
 
Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider pdfFormatProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
Telerik.Windows.Documents.Fixed.Model.RadFixedDocument fixedDocument = pdfFormatProvider.Import(fileBytes);

After having the document imported, you can now convert its pages to images through the Export method. In this example, each page is saved in a separate file.

SkiaImageFormatProvider imageProvider = new SkiaImageFormatProvider();
 
foreach (RadFixedPage page in fixedDocument.Pages)
{
    byte[] resultImage = imageProvider.Export(page);
    int pageNumber = fixedDocument.Pages.IndexOf(page) + 1;
    File.WriteAllBytes(@"C:\Temp\Images " + pageNumber + ".png", resultImage);
}

That is all you need to do if you need to read an existing file and export its pages to images. Check out the SkiaImageFormatProvider documentation article if you are curious about other export settings. I hope you will enjoy the new functionality!

Try Out the New Feature & Share Your Feedback

Head over and download a free trial. If you are an active license holder, you can grab the latest bits from Your Telerik Account or update your NuGet package references to the latest ones directly in your .NET solutions.

Share your thoughts with us on our Feedback Portal and help us shape the future of Telerik Document Processing!


This content originally appeared on Telerik Blogs and was authored by Tanya Dimitrova


Print Share Comment Cite Upload Translate Updates
APA

Tanya Dimitrova | Sciencx (2022-12-15T14:17:02+00:00) Turn PDF Pages Into Images With PdfProcessing. Retrieved from https://www.scien.cx/2022/12/15/turn-pdf-pages-into-images-with-pdfprocessing/

MLA
" » Turn PDF Pages Into Images With PdfProcessing." Tanya Dimitrova | Sciencx - Thursday December 15, 2022, https://www.scien.cx/2022/12/15/turn-pdf-pages-into-images-with-pdfprocessing/
HARVARD
Tanya Dimitrova | Sciencx Thursday December 15, 2022 » Turn PDF Pages Into Images With PdfProcessing., viewed ,<https://www.scien.cx/2022/12/15/turn-pdf-pages-into-images-with-pdfprocessing/>
VANCOUVER
Tanya Dimitrova | Sciencx - » Turn PDF Pages Into Images With PdfProcessing. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/12/15/turn-pdf-pages-into-images-with-pdfprocessing/
CHICAGO
" » Turn PDF Pages Into Images With PdfProcessing." Tanya Dimitrova | Sciencx - Accessed . https://www.scien.cx/2022/12/15/turn-pdf-pages-into-images-with-pdfprocessing/
IEEE
" » Turn PDF Pages Into Images With PdfProcessing." Tanya Dimitrova | Sciencx [Online]. Available: https://www.scien.cx/2022/12/15/turn-pdf-pages-into-images-with-pdfprocessing/. [Accessed: ]
rf:citation
» Turn PDF Pages Into Images With PdfProcessing | Tanya Dimitrova | Sciencx | https://www.scien.cx/2022/12/15/turn-pdf-pages-into-images-with-pdfprocessing/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.