Loading an image

Feb 17, 2012 at 1:25 PM


I want to show an png in my pdf, but I always get an error. I am using the following code to read the image:

WebClient client = new WebClient();
                client.OpenReadCompleted += (sender, e) =>
                    if (e.Error == null)
                        this.polLogo = XImage.FromStream(e.Result);
                client.OpenReadAsync(new Uri("http://localhost:6976/ClientBin/Resources/Images/Icons/images.png", UriKind.Absolute));

Then I use this one to draw it:

this.document = new PdfDocument();
                PdfPage page = this.document.AddPage();
                page.Size = PageSize.A4;

                XGraphics gfx = XGraphics.FromPdfPage(page);

                // Rectangle to write text in
                XRect lRect = new XRect(0.0, 20.0, page.Width.Value, 20);

                gfx.DrawImage(this.polLogo, 50, 50);

                // Dispose graphics object

While the method DrawImage following exception (translated into english from me) is thrown:

"The Value must not be null
Parametername: value

   bei PdfSharp.Pdf.PdfDictionary.DictionaryElements.set_Item(String key, PdfItem value)
   bei PdfSharp.Pdf.Advanced.PdfImage.Merge(PdfDictionary other)
   bei PdfSharp.Pdf.Advanced.PdfImage..ctor(PdfDocument document, XImage source_image)
   bei PdfSharp.Pdf.Advanced.PdfImageTable.GetImage(XImage image)
   bei PdfSharp.Pdf.PdfPage.GetImageName(XImage image)
   bei PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.GetImageName(XImage image)
   bei PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.Realize(XImage image)
   bei PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.DrawImage(XImage image, Double x, Double y, Double width, Double height)
   bei PdfSharp.Drawing.XGraphics.DrawImage(XImage image, Double x, Double y)
   bei PdfSharp.Drawing.XGraphics.DrawImage(XImage image, Int32 x, Int32 y)
   bei Polizeiliche_Fotografie.Code.Helper.PdfHelper.CreatePdf(String quizName, String userName, Int32 reachablePoints, Int32 reachedPoints)"

The image is read correctly but it is not drawn. Can somebody help me? I use Silverlight 4.

Apr 9, 2012 at 7:54 AM

It seems that silverPdf not support PNG files.. try use JPG or TIFF