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. Image for the cookie policy date

Exception on code working in version that now doesn't work on version

I worked on a project some time ago, that used Syncfusion for WinRT version
it had some pdf manipulation, such as adding images to the pdf. After some effort it was working and the part of the code was something like this

foreach (var image in this.images)   //image is type Windows.Ui.Xaml.Controls.Image
                    var bitmap = image.Source as ImageSource;
                    var index = bitmaps.IndexOf(bitmap);
                    var signature = signatures.ElementAt(index);
                    var bytes = await signature.Data.EncodePngToJpeg();  //returns bytes of png image converted to jpg

                    PdfImage pdfImage;
                    using (var memoryStream = new MemoryStream(bytes))
                        pdfImage = PdfImage.FromStream(memoryStream);

      var transform = image.RenderTransform as CompositeTransform;

                    var x = (image.Margin.Left + transform.TranslateX + horizontalOffset) * 100 / pdfViewer.Zoom - 10;
                    var y = (image.Margin.Top + transform.TranslateY + verticalOffset) * 100 / pdfViewer.Zoom - 10;

                    var firstPage = pdfDocument.Pages[pdfViewer.PageNumber - 1];
                    var pageHeight = firstPage.Size.Height;
                    var pageWidth = firstPage.Size.Width;

                    var selpage = pdfViewer.PageNumber;

                    var pagn = selpage - 1;
                    if (pagn < 0)
                        pagn = 0;

                    var ss = pdfViewer.GetDescendantsOfType<ScrollViewer>();
                    var hh = ss.ElementAt(3);
                    float VertOff = (float)hh.VerticalOffset;
                    float VertOff2 = (VertOff * 100 / pdfViewer.Zoom) - ((pagn) * (pageHeight * 1.325f));

                    var page = pdfDocument.Pages[pagn];
                    var graphics = page.Graphics;

                    var width = image.Width;
                    var height = image.Height;

                    //float fWidth = (float)width;
                    //float fHeight = (float)height;
                    fWidth = 165f * 0.50f;
                    fHeight = 110f * 0.50f;

                    graphics.ScaleTransform(0.75f, 0.75f);
                    graphics.DrawImage(pdfImage, (float)x, (float)y + VertOff2, fWidth, fHeight);   // <-- exception is here 


then i installed the WinRT trial version ( and i started to get this exception 

A first chance exception of type 'System.NullReferenceException' occurred in Syncfusion.Pdf.WinRT.DLL
System.NullReferenceException' : {"Object reference not set to an instance of an object."}

with this StackTrace:

   at Syncfusion.Pdf.Graphics.PdfBitmap.SetColorSpace()
   at Syncfusion.Pdf.Graphics.PdfBitmap.Save()
   at Syncfusion.Pdf.Graphics.PdfGraphics.DrawImage(PdfImage image, Single x, Single y, Single width, Single height)
   at Gapp_metro.Pages.PdfPage.<OnSaveButtonClick>d__25.MoveNext()

Did anything changed between versions that might be giving me an error?

3 Replies

PH Praveenkumar H Syncfusion Team April 16, 2015 04:41 AM UTC

Hi Ric,

Currently Essential PDF Winrt supports the following image formats.

1. Jpeg
2. PNG
3. Tiff
4. Gif

Please try the PNG image without convert it to jpeg, we have attached the sample project for your reference, Please try this and let us know the result also please send us your input image we will check and let you know the details.


With Regards,

RS Ric Silva April 16, 2015 01:46 PM UTC

I commented the png to jpg conversion and used the bytes of the png file directly and the result was the same.
the image comes from a webservice and they are the same i used when i had version

not quite sure what the problem is.
the image im using is attached.

Attachment: signature_5a49fbc8.zip

PH Praveenkumar H Syncfusion Team April 17, 2015 06:43 AM UTC

Hi Ric,

Thank you for your update,

We are afraid that we are not able to reproduce the issue, we have attached the simplified sample project with the output document.
Can you please modify the sample to reproduce the issue and send back the sample to us, it will help us to investigate further in this.

With Regards,

Live Chat Icon For mobile
Up arrow icon