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
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
Our thoughts here at Progress are with those affected by the outbreak.
![](/forums/images/avatarimages/default.gif)
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
Our thoughts here at Progress are with those affected by the outbreak.
Hello Herbert,
In such cases, the COM threading model for the application has to be a single-threaded apartment (STA), meaning that a STAThreadAttribute tag "[STAThread]" should be placed on the class:
[STAThread]
private static void Main(string[] args)
I hope this helps.
Regards,
Yoan