Convert PDF to JPG

10 posts, 0 answers
  1. Blas
    Blas avatar
    56 posts
    Member since:
    Dec 2007

    Posted 28 May 2015 Link to this post

    Hi,

    Is there any way to convert/rasterize an existing PDF file to JPG file(s) using PDFProcessing library?

    Regards

    Blas

  2. Tanya
    Admin
    Tanya avatar
    764 posts

    Posted 01 Jun 2015 Link to this post

    Hello Blas,

    RadPdfProcessing is independent of UI library and has no notion of the way the document should be visualized. This is why is not possible to export a PDF document to image using this library.

    In order to achieve your goal, you could use the PdfViewer control to import the document and create images from its pages using the ThumbnailFactory class. The following snippet demonstrates how to achieve this for the first page of the RadFixedDocument:

    PdfFormatProvider docProvider = new PdfFormatProvider();
    var data = docProvider.Export(doc);
     
    PdfFormatProvider provider = new PdfFormatProvider(new MemoryStream(data), FormatProviderSettings.ReadOnDemand);
    this.viewer.Document = provider.Import();
     
    ThumbnailFactory factory = new ThumbnailFactory();
    RadFixedPage page = this.viewer.Document.Pages[0];
    ImageSource source = factory.CreateThumbnail(page, page.Size);
     
    Image image = new Image();
    image.Source = source;
     
    // This adds white background, because the image that ThumbnailFactory creates is transparent.
    Grid grid = new Grid();
    grid.Background = Brushes.White;
    grid.Children.Add(image);
     
    Size size = new Size(600, 800);
    grid.Measure(size);
    grid.Arrange(new Rect(new Point(0, 0), size));
     
    RenderTargetBitmap bitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
    bitmap.Render(grid);
      
    using (var fileStream = new FileStream("test.jpeg", FileMode.Create))
    {
        System.Windows.Media.Imaging.BitmapEncoder encoder = new JpegBitmapEncoder();
        ExportExtensions.ExportToImage(grid, fileStream, encoder);
    }

    The ThumbnailFactory returns a picture of the content of the document and it may not have background set. The additional steps in the snippet above are used to set a background for the image.

    Hope this helps.

    Regards,
    Tanya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Tanya
    Admin
    Tanya avatar
    764 posts

    Posted 01 Jun 2015 Link to this post

    I am sorry I misled you in my previous reply.

    You should be aware that the example from my previous post will work only for the RadPdfViewer from the Telerik UI for WPF suite. You could refer the corresponding dll-s in your project and convert the document.

    If this doesn't fit your needs, you could check this article, which explains how to create a printable panel.

    Regards,
    Tanya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  4. Blas
    Blas avatar
    56 posts
    Member since:
    Dec 2007

    Posted 02 Jun 2015 in reply to Tanya Link to this post

    Thank you Tanya for your answer, although I couldn't test it, because the code provided uses the ThumbnailFactory WPF class and my project is Winform.

     Is it possible to implement this funcionality in Winform?

    Regards

    Blas

  5. Blas
    Blas avatar
    56 posts
    Member since:
    Dec 2007

    Posted 02 Jun 2015 in reply to Blas Link to this post

    Hi Tania,

     I didn't see your last response... In any case, I included in my project some WPF dlls but I'm having some problems.

     In the last line, I get an VS error saying "page: a value of the type Telerik.Windows.Pdf.Documents.Fixed.Model.RadFixedPage cannot be converted to the type Telerik.Windows.Documents.Fixed.Model.RadFixedPage.

    Viewer.LoadDocument("C:\temp\file.pdf")
    Dim factory As New Telerik.Windows.Documents.UI.ThumbnailFactory()
    Dim page As RadFixedPage = Viewer.Document.Pages.Item(0)
     
    Dim source As System.Windows.Media.ImageSource = factory.CreateThumbnail(page, New Windows.Size(page.Size.Width, page.Size.Height))

     

  6. Blas
    Blas avatar
    56 posts
    Member since:
    Dec 2007

    Posted 03 Jun 2015 in reply to Blas Link to this post

    Hi Tanya,

     I've opened a support ticket.

    Thank you

    Blas

  7. Mikhail
    Mikhail avatar
    2 posts
    Member since:
    Jun 2016

    Posted 23 Jul 2018 Link to this post

    Where can I get (download) library Telerik.Windows.Documents.UI to use ThumbnailFactory?

    I have:

    Telerik.Windows.Documents.Core

    Telerik.Windows.Documents.Fixed

    Telerik.Windows.Documents.Flow

    Telerik.Windows.Documents.Flow.FormatProviders.Pdf

    Telerik.Windows.Documents.Spreadsheet

    Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml

    Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf

    Telerik.Windows.Maths

    Telerik.Windows.Zip

     

    Thank you

  8. Tanya
    Admin
    Tanya avatar
    764 posts

    Posted 24 Jul 2018 Link to this post

    Hello Mikhail,

    The ThumbnailFactory class is part of the API of RadPdfViewer for WPF. You can download the suite through your telerik.com account and more information on how to use the PdfViewer control you can find in the related documentation topics: Getting StartedExporting Fixed Page to Image.

    Hope this is helpful.

    Regards,
    Tanya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  9. Mikhail
    Mikhail avatar
    2 posts
    Member since:
    Jun 2016

    Posted 24 Jul 2018 in reply to Tanya Link to this post

    Thank you Tanya,

    From what version of Telerik I can get all dll libraries? I can't find Telerik.Windows.Controls.FixedDocumentViewers.dll .

    Telerik.Windows.Controls.dll
    Telerik.Windows.Controls.FixedDocumentViewers.dll
    Telerik.Windows.Documents.Core.dll
    Telerik.Windows.Documents.Fixed.dll
    Telerik.Windows.Zip.dll

  10. Tanya
    Admin
    Tanya avatar
    764 posts

    Posted 25 Jul 2018 Link to this post

    Hello Mikhail,

    The Telerik.Windows.Controls.FixedDocumentViewers.dll file is available since the Q1 2012 release of UI for WPF and should be present in the Binaries folder if you have a newer version. In case you are facing any issues using the PdfViewer control, I would like to ask you to submit your questions in the forum section dedicated to the specific component: https://www.telerik.com/forums/wpf/pdfviewer. Thank you in advance.

    Regards,
    Tanya
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top