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.
Unfortunately, activation email could not send to your email. Please try again.

Need help in creating pdf with images

Thread ID:

Created:

Updated:

Platform:

Replies:

117268 Sep 19,2014 08:34 AM Sep 22,2014 12:41 AM WinRT 1
loading
Tags: PDF
winny
Asked On September 19, 2014 08:34 AM

Hi,

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);
            //g.DrawImage()
        }

        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 12:41 AM

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.

 

Thanks,

Karthikeyan.C


CONFIRMATION

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.

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.

;