Flip PDF Pages Into Photos With PdfProcessing


Take a look at the brand new performance of Telerik PdfProcessing to transform PDF pages to photographs.

Lots of you requested us to give you the power to export your paperwork or components of them to photographs in .NET Commonplace/.NET Core purposes. As we’re all the time listening to your suggestions, over the last launch we labored exhausting to give you
this performance and I’ll current it on this weblog submit.

To make it doable for all platforms utilizing the .NET Commonplace model of PdfProcessing to create photographs, the
library makes use of a third-party instrument for picture technology—SkiaSharp. A number of picture codecs are supported,
and you can even select whether or not to carry out the exporting operation synchronously or asynchronously.

Let’s take a more in-depth take a look at the API associated to the brand new performance. The entry level making all of the magic is the SkiaImageFormatProvider class. If you’re already utilizing PdfProcessing, you need to be conversant in the format suppliers and the way they work. For all the remainder, briefly, the format suppliers expose Import and Export strategies that allow you to parse a doc into the interior mannequin of the library or save the
info from this mannequin right into a doc file, respectively.

Let’s Create an Instance

To raised show the performance and its utilization, I’ll information you step-by-step on creating an software that opens an current PDF doc and converts its pages into photographs.

First issues first—I’ll create a console software and add the dependencies we have to use the PdfProcessing library. For extra comfort, I’ll straight go along with the Telerik.Paperwork.Mounted.FormatProviders.Picture.Skia NuGet
bundle that may obtain all of its dependencies mechanically:

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

In case you like including references to the .dll information, right here is the listing of required assemblies:

  • Telerik.Paperwork.Core
  • Telerik.Paperwork.Mounted
  • Telerik.Zip
  • Telerik.Paperwork.Mounted.FormatProviders.Picture.Skia

As I discussed earlier, the picture exporting performance is dependent upon SkiaSharp, thus you will have so as to add dependencies to its binaries as effectively:

  • The SkiaSharp NuGet bundle
  • The SkiaSharp.NativeAssets.* NuGet bundle. This bundle could differ in accordance with the used platform. There are variations for Home windows, MacOS, Linux, WebAssembly, Android, iOS and others.

As soon as we’re prepared with the setup, we are able to proceed so as to add some logic to our software. Step one we have to implement is to learn the PDF doc we have already got:

byte[] fileBytes = File.ReadAllBytes("SampleDocument.pdf");
 
Telerik.Home windows.Paperwork.Mounted.FormatProviders.Pdf.PdfFormatProvider pdfFormatProvider = new Telerik.Home windows.Paperwork.Mounted.FormatProviders.Pdf.PdfFormatProvider();
Telerik.Home windows.Paperwork.Mounted.Mannequin.RadFixedDocument fixedDocument = pdfFormatProvider.Import(fileBytes);

After having the doc imported, now you can convert its pages to photographs by way of the Export technique. On this instance, every web page is saved in a separate file.

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

That’s all it’s good to do if it’s good to learn an current file and export its pages to photographs. Take a look at the SkiaImageFormatProvider documentation article if you’re interested by different export settings. I hope you’ll take pleasure in the brand new performance!

Attempt Out the New Characteristic & Share Your Suggestions

Head over and obtain a free trial. If you’re an lively license holder, you may seize the most recent bits from Your Telerik Account or replace your NuGet bundle references to the most recent ones straight in your .NET options.

Share your ideas with us on our Suggestions Portal and assist us form the way forward for Telerik Doc Processing!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles