export/extract image bytes of each page

6 posts, 2 answers
  1. Mark
    Mark avatar
    4 posts
    Member since:
    Jun 2012

    Posted 05 Sep 2012 Link to this post

    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
  2. Mark
    Mark avatar
    4 posts
    Member since:
    Jun 2012

    Posted 09 Sep 2012 Link to this post

    Anyone have any help or ideas on this? I really need a resolution to this issue ASAP.

    Thanks for any help you can give.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 10 Sep 2012 Link to this post

    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.

  5. Mark
    Mark avatar
    4 posts
    Member since:
    Jun 2012

    Posted 10 Sep 2012 Link to this post

    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?
  6. Answer
    Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 11 Sep 2012 Link to this post

    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.

  7. Mark
    Mark avatar
    4 posts
    Member since:
    Jun 2012

    Posted 11 Sep 2012 Link to this post

    Hi Kammen, thanks for this, you may close this issue.
Back to Top
UI for WPF is Visual Studio 2017 Ready