Select to view content in your preferred language

Adding a legend image using silverPDF

975
3
11-01-2010 07:47 AM
DavidFlack
Regular Contributor
Hi everyone,

I'm using PDFsharp to create PDFs from my Silverlight 4 app- see http://forums.arcgis.com/threads/8582-Create-PDF for reference.

Since the map product is basic, I'm using some of the objects provided by PDFsharp to add a title, border, disclaimer, etc.  However, I'm encountering an error when I try to add my legend image to the output.  Since I have references in my project, I should be able to use the following two lines of code to do this:

XImage imgLegend = XImage.FromFile("Graphics/Legend.png");
gfx.DrawImage(imgLegend, 500, 500);

Problem: I get the error "'PdfSharp.Drawing.XImage.FromFile(string)' is obsolete: "'Can't use this in Silverlight!'"  Has anyone else had this problem or found a workaround for it?  Thanks for any help.  I will cross-post on the PDFSharp wiki.

Dave
0 Kudos
3 Replies
ShenWang
Emerging Contributor
Did you figure the problem out? I have the same problem. Could you please let me know the solution for it?

Thanks
0 Kudos
DominiqueBroux
Esri Frequent Contributor

"'PdfSharp.Drawing.XImage.FromFile(string)' is obsolete: "'Can't use this in Silverlight!'"

I don't know PdfSharp, but I guess the problem is a general SL restrictions : you can't access directly the local files.

The workarounds maybe:
    - to use OpenFileDialog to open the file
    - to get a stream instead of a file and create the XImage from a stream
    - to store the file in the IsolatedStorage
0 Kudos
MartaMoreno
New Contributor
Hi,

Sorry for my english (I'm spanish). If you want add an image, you must follow this steps:

- Add the image file to your silverlight project. When you select this file within the Solution Explorer, the Properties window allows you to choose a given �??Build
Action�??. Select "embedded resource".

- Now, you can open this file win XImage.FromStream (FromFile is obsolete).

For example (my picture is in Plantilla/images folder):

                            XGraphics gLeyenda = XGraphics.FromPdfPage(page);
                            Assembly myAssembly = Assembly.GetExecutingAssembly();
                            Stream myStream = myAssembly.GetManifestResourceStream("Plantilla.Images.LeyendaMapa.JPG");
                            XImage leyenda = XImage.FromStream(myStream);
                            gLeyenda.DrawRectangle(pen, 655, 40, leyenda.Width - 35, leyenda.Height - 65);
                            gLeyenda.DrawImage(leyenda, 660d, 50d);
                            gLeyenda.Dispose();

I hope help you.

Marta
0 Kudos