This is a migrated thread and some comments may be shown as answers.

Converting PDF to Image in MVC application

3 Answers 905 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 01 Apr 2020, 08:40 PM

Hi,

I am trying to convert a PDF to an image server side in our .Net MVC application.

I have seen this forum post https://www.telerik.com/forums/convert-pdf-to-jpg and it explains how to convert a pdf to an image but those libraries don't seem to be available in an MVC application. 

Is there a solution that I can use for my application?

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 03 Apr 2020, 10:28 AM

Hello Marcus,

The Telerik Document Processing libraries comes as a part of the UI for ASP.NET MVC. For more information, you can check the Telerik Document Processing help article in the UI for ASP.NET MVC documentation.

If you need any further assistance with example implementation, please, let us know.

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Marcus
Top achievements
Rank 1
answered on 03 Apr 2020, 01:30 PM
I understand this as this is what I have been using to create PDF files. What I want to know is if there is a way to convert PDF files into image files as I have found no documentation on this.
0
Martin
Telerik team
answered on 06 Apr 2020, 08:08 AM

Hi Marcus,

I am sorry I didn't understand your question right. Currently, the PdfProcessing library doesn't provide such functionality to export RadFixedPage to an image. We have this item logged in our backlog: PdfProcessing: Export document pages to images. You can cast your vote for the implementation as well as subscribe to the task by clicking the Follow button so you can receive updates about status changes.

Until this feature is developed, I would like to suggest, if it is an option for you, to use the RadPdfViewer control form the UI for WPF suite (which is the example you have found in our forum) to create images from the RadFixedDocument pages using the ThumbnailFactory class. Check the following example: 

byte[] data = GetDocumentData();
    
RadPdfViewer pdfViewer = new RadPdfViewer();

PdfFormatProvider provider = new PdfFormatProvider(new MemoryStream(data), FormatProviderSettings.ReadAllAtOnce);
pdfViewer.Document = provider.Import();

int pageNumber = 0;
RadFixedPage page = pdfViewer.Document.Pages[pageNumber];

ThumbnailFactory factory = new ThumbnailFactory();

ImageSource imageSource = factory.CreateThumbnail(page, page.Size);

Image image = new 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);

string exportedFileName = "Exported.tiff";
using (FileStream fileStream = new FileStream(exportedFileName, FileMode.Create))
{
    BitmapEncoder encoder = new TiffBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(bitmap));
    encoder.Save(fileStream);
}

I am attaching a sample project demonstrating this functionality as well.

For more information where to find the required binaries, you can check the UI for WPF Download Product Files help article.

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
PdfProcessing
Asked by
Marcus
Top achievements
Rank 1
Answers by
Martin
Telerik team
Marcus
Top achievements
Rank 1
Share this question
or