We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Need help in creating pdf with images

Thread ID:





117268 Sep 19,2014 12:34 PM UTC Sep 22,2014 04:41 AM UTC WinRT 1
Tags: PDF
Asked On September 19, 2014 12:34 PM UTC


I have a requirement wherein I have to create PDF out of the framework elements. Say, I have labels, textboxes. I have to capture an image for the same and insert it into a PDF. As I came to know, only jpegs are supported, so I tried creating a jpeg for the control and then creating a pdf. Here is the code I am using:

public sealed partial class CustomControl: UserControl
 public async Task Print(StorageFile file,)
            //Creates a new PDF document.
            PdfDocument doc = new PdfDocument();

            //Adds a page to the document.
            PdfPage page = doc.Pages.Add();

            //Creates Pdf graphics for the page.
            PdfGraphics g = page.Graphics;

            //Creates a solid brush.
            PdfBrush brush = new PdfSolidBrush(new PdfColor(255,0,0));

            //Sets the font.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);

            PdfImage image = new PdfBitmap(await CreateBitmap(this));

            g.DrawImage(image, new System.Drawing.PointF(10, 10));

            await doc.SaveAsync(file);

        async public Task<System.IO.Stream> CreateBitmap(FrameworkElement element)
            // render element to image (WinRT)
            var renderTargetBitmap = new RenderTargetBitmap();
            await renderTargetBitmap.RenderAsync(element);
            var wb = new WriteableBitmap(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight);
            (await renderTargetBitmap.GetPixelsAsync()).CopyTo(wb.PixelBuffer);
            var rect = new Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight);

            StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;

            await wb.SaveToFile(folder, "test1.jpeg");
            StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("test1.jpeg");
            Stream stream = await file.OpenStreamForReadAsync();
            return stream;

But this still gives me the same error that jpeg is only supported. Can you please let me know where I am going wrong.

KarthikeyanC [Syncfusion]
Replied On September 22, 2014 04:41 AM UTC

Hi Winny,

Thank you for using Syncfusion Products.


Could you please provide us the generated image("test1.jpeg"), which you are trying to draw in PDF document so that it will be easy for our investigation.





This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon