PDF Thumbnail returns transparent images

4 posts, 0 answers
  1. Iwhp
    Iwhp avatar
    40 posts
    Member since:
    Dec 2009

    Posted 10 Nov 2014 Link to this post

    Why does the following code return a transparent image?
    The WHITE is transparent.

    PdfFormatProvider provider = new PdfFormatProvider(file, FormatProviderSettings.ReadOnDemand);
    RadFixedDocument document = provider.Import();
    ThumbnailFactory factory = new ThumbnailFactory();
    RadFixedPage page = document.Pages[0];
    System.Windows.Media.ImageSource source = factory.CreateThumbnail(page, page.Size);

    var image = (BitmapSource)source;
    BitmapEncoder encoder = new PngBitmapEncoder();
    using (var ms = new MemoryStream())
       ms.Position = 0;
       return ms;

    Thankx, Harry

  2. Deyan
    Deyan avatar
    126 posts

    Posted 12 Nov 2014 Link to this post

    Hello Harry,

    Thank you for contacting us.

    You can create image and place it in a grid with white background to achieve the desired result. The following code snippet shows how to create such image from the first page of a document:
    int pageNumber = 0;
    RadFixedPage page = this.pdfViewer.Document.Pages[pageNumber];
    var tf = new ThumbnailFactory();
    ImageSource imageSource = tf.CreateThumbnail(page, new Size(page.ActualWidth, page.ActualHeight));
    Image image = new Image();
    image.Width = page.ActualWidth;
    image.Height = page.ActualHeight;
    image.Source = imageSource;
    Grid container = new Grid();
    container.Background = new SolidColorBrush(Colors.White);
    container.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
    container.Arrange(new Rect(new Point(0, 0), container.DesiredSize));
    RenderTargetBitmap bitmap = new RenderTargetBitmap((int)page.ActualWidth, (int)page.ActualHeight, 96, 96, PixelFormats.Default);
    var encoder = new PngBitmapEncoder();
    using (var fs = new FileStream(@"C:\test.png", FileMode.Create))

    I hope this is helpful. If you have any other questions or concerns please do not hesitate to contact us again.

    the Telerik team

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. Chris
    Chris avatar
    30 posts
    Member since:
    Oct 2015

    Posted 23 Feb in reply to Deyan Link to this post




    >Grid container = new Grid();

    What is the namespace/assembly of Grid ?


    Maybe the code should list the namespace briefly (for novices):

    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using Telerik.Windows.Documents.Fixed.FormatProviders;
    using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
    using Telerik.Windows.Documents.Fixed.Model;
    using Telerik.Windows.Documents.Fixed.Model.Objects;
    using Telerik.Windows.Documents.UI;


    Best regards





    Grid container = new Grid();
    Grid container = new Grid();
    Grid container = new Grid();
    Grid container = new Grid();
  4. Tanya
    Tanya avatar
    376 posts

    Posted 25 Feb Link to this post

    Hello Chris,

    The Grid class resides in the System.Windows.Controls namespace. In order to use it, you will need to add a reference to the PresentationFramework assembly.

    The next snippet shows all the required namespaces for using the snippet from Deyan's post.
    using System.IO;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using Telerik.Windows.Documents.Fixed.Model;
    using Telerik.Windows.Documents.UI;

    Hope this helps.

    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
Back to Top