Create PDF ?

8955
76
07-20-2010 06:02 AM
CraigPerreault
New Contributor II
Does anyone have a code sample to create a PDF file using the Silverlight API?
0 Kudos
76 Replies
PauloVerissimo
New Contributor
An easier option is to print using a pdf printer driver.
You can choose what to print, in this example, I only print the Map.
Here is the C# code:
...
using System.Windows.Ink;
using System.Windows.Printing;
private void buttonPrint_Click(object sender, System.Windows.RoutedEventArgs e)
{     PrintDocument document = new PrintDocument();
      document.PrintPage += (s, args) =>
      {    args.PageVisual = Map;
      };
      document.Print("Map");
}
0 Kudos
MikkelHylden
Occasional Contributor
@ErikE :
It looks like it should be working.  In my code, when I click my print button, it runs the following to set up the map:

            PDFExporter PDFNew = new PDFExporter();
            PDFNew.SetMap(MyMap);
..continue on my merry way...
Can you tell if your PDFEXporter class does not have a _Map member variable?  Also, be sure you've instantiated your PDFExporter class, as the member variables are not static.

@MCederholm:
I did get my image export working - I just had to set/modify a few additional parameters to get the image back correctly.  Thanks.
0 Kudos
ErikEngstrom
Occasional Contributor II
@ErikE :
It looks like it should be working.  In my code, when I click my print button, it runs the following to set up the map:

            PDFExporter PDFNew = new PDFExporter();
            PDFNew.SetMap(MyMap);
..continue on my merry way...

Thanks mhylden! That did the trick...

I can now get an export image to PDF, but my tiled map service doesn't seem to be drawing. My Dynamic map and graphic layers seem to show up fine.:confused:
0 Kudos
JoeJeurissen
New Contributor
Hello,

I am fairly new to Silverlight/ESRI and I am trying to insert my map and all of its layers into a PDF file.  I have used the method of converting a map to a PDF from this thread and everything works fine.  I have also looked into this example and have tested them both.  The example I have posted provides much better quality because the map is not being converted to a bitmap.  The only problem is that it only converts 1 map layer into the PDF. I have a ArcGISTiledMapServiceLayer, several ArcGISDynamicMapServiceLayers, and several GraphicsLayers that need to be inside of the same PDF.  Does somebody know of a way to do this or would be kind enough to post an example of how this can be done.

Thank you.
0 Kudos
MarkCederholm
Occasional Contributor III
FYI, the PDF exporter download has included an example user control since November.  I've never seen a problem with tiled, dynamic, or graphic layers.

http://www.pierssen.com/arcgis10/silverlight.htm
0 Kudos
JoeJeurissen
New Contributor
Sorry if I wasn't clear.  I have the PDFExporter up and running fine and it works fine with all of my layers.  The quality of the PDF file is the problem.  The PDFExporter causes the map to become very 'pixelated'.

The example here http://kiwigis.blogspot.com/2010/11/how-to-export-map-to-pdf-client-side.html results in a much better quality because it is taking a map layer and putting it straight into a PDF file.

My problem is that I am not sure how to put all of the layers from my map and put it into a PDF using the second solution.  I can get my ArcGISTiledMapServiceLayer to appear OR I can get one of my ArcGISDynamicMapServiceLayers to appear, but I can't get them to appear all together.
0 Kudos
adamestrada
New Contributor
All,

I have yet to get this thing working. I added a click event to a button in my silverlight business application which calls the code example from here. http://www.pierssen.com/arcgis10/silverlight.htm

        private void Map2PDF_Click(object sender, RoutedEventArgs e)
        {
            Map2PDF map2pdf = new Map2PDF();
            map2pdf.Show();
        }


I changed the file type from a UserControl to a ChildWindow and the dialog does invoke, I just can't seem to get it to find the map and all of it's elements. I keep getting the "Map not Set" error.

Does anyone have an idea on how to fix this? In Home.xaml I have defined the map part as

<esri:Map x:Name="Map" Loaded="Map_Loaded" Extent="-15000000,2000000,-7000000,8000000">


The app still cannot find the Map.

Thanks in advance,
Adam
0 Kudos
MarkCederholm
Occasional Contributor III
There's a section in the sample user control code marked "Methods called by the MainPage".
0 Kudos
adamestrada
New Contributor
Hi Mark,

To which code are you referring to? Can you pls give me a file to look at as there are several projects out there and I am all kinds of confused at this point.

Thanks,
Adam
0 Kudos
MarkCederholm
Occasional Contributor III
I guess I really don't explain the contents of the zip file at http://www.pierssen.com/arcgis10/silverlight.htm -- maybe I should add a ReadMe.txt with more info.  Anyway, PDFExporter.cs is the actual PDF export class, and ExportPDF.xaml.cs is the code-behind for a sample user control which uses the class.
0 Kudos