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

export/extract image bytes of each page

5 Answers 270 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 06 Sep 2012, 02:47 AM
Hi all,

Im trying to discover the features of the RadPDFViewer control and I really want to either save each page to a JPG/PNG/etc file or perhaps just 'get' the bytes/memory stream of each page that I can use in various places in my WPF app.

I saw the filters API, but I cannot find examples or code samples on this API, can what I desire be achieved?

Thanks a lot
Mark

5 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 10 Sep 2012, 12:46 AM
Anyone have any help or ideas on this? I really need a resolution to this issue ASAP.

Thanks for any help you can give.
0
Accepted
Kammen
Telerik team
answered on 10 Sep 2012, 11:16 AM
Hi Mark,

RadPdfViewer is normally used to display PDF documents in business applications. It is not the best way to export a PDF page to image. However, you can use the FixedDocumentSinglePagePresenter in your case. Here is a sample code of how you can create an image from a PDF page.

Stream stm = Application.GetResourceStream(new Uri("pack://application:,,,/Sample.pdf", UriKind.RelativeOrAbsolute)).Stream;
PdfFormatProvider provider = new PdfFormatProvider(stm, FormatProviderSettings.ReadOnDemand);
RadFixedDocument document = provider.Import();
FixedDocumentSinglePagePresenter container = new FixedDocumentSinglePagePresenter();
RadFixedPage page = document.Pages[0];
container.ContentCreated += (s, ea) =>
{
    RadBitmap rbm = new RadBitmap((int)page.ActualWidth, (int)page.ActualHeight, container);
    Window w = new Window();
    Image img = new Image();
    img.Source = rbm.Bitmap;
    w.Content = img;
    w.Show();
};
container.Page = page;


Regards,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mark
Top achievements
Rank 1
answered on 10 Sep 2012, 12:24 PM
Hi Kammen,

Thanks a lot for the reply, when you say that its not the best way, do you have any guidance on the best way to get the pages from a PDF into JPG or Image controls? Does Telerik have any libraries for this?
0
Accepted
Kammen
Telerik team
answered on 11 Sep 2012, 08:20 AM
Hi Mark,

We do not have such a library. However, we have found an open-source solution for converting PDF to PNG and JPG. You can find it here. It represents a C# wrapper for the Ghostscript library. We have tested it and it seems to work fine.

You should choose for yourself which way best suits your needs.


Regards,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mark
Top achievements
Rank 1
answered on 12 Sep 2012, 04:51 AM
Hi Kammen, thanks for this, you may close this issue.
Tags
PDFViewer
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Kammen
Telerik team
Share this question
or