Create PDF ?

8820
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
JayKappy
Occasional Contributor
Do you have by any chance a project that you can post with your code?  Maybe something truncated down to just the print code?  I know it is a lot to ask...and as you mentioned there are a lot of holes there...

Would be nice to see how you created the popup that alows the user to specify the map name and where you are storing it and applyign it to the code for the export
0 Kudos
JonathanHouck
New Contributor III
The map title is passed into the GP service in one of the parameters as a string variable.  So you could set the variable equal to a textbox.Text that you provide for the user to enter the title, then execute the ExportTask on a button click event handler (or whatever you want).

I'll look into hosting a project with as much of the code as I can, but in the meantime I'd be happy to answer any other questions you have about how the whole thing works.
0 Kudos
JayKappy
Occasional Contributor
What code are the event handlers calling....the 30 plus lines of code cant be all thats needed....I can probably handle passign the varaibles from a form or window to the parameters...or at least hard code them for the time being..

1. I think you are specifying the parameters....adn teh accessign them with ExportTask.SubmitJobAsync(jobParameters)...is that correct?

2. As for the envent handler : ExportTask.JobCompleted += New EventHandler(Of JobInfoEventArgs)(ExportTask_JobCompleted)
What code is this calling?

I am starting from scratch so I assume that in a Button click I define the parameters and then run the Event Handlers????

Thank you for your time and help...it is greatly apprecaited.
0 Kudos
JonathanHouck
New Contributor III
I'll try my best to explain this correctly... I apologize in advance, I'm a geographer that's learned to write some code, not a CS guy.

From the link Patrick posted above, we got the Python script that ESRI staff developed for doing a print with Arcpy.mapping. The python script gets published in ArcServer as a geoprocessing service.  I'm sure you know all this already, but I'm starting from the beginning.  This geoprocessing service accepts a series of parameters that are passed to it, and then passes these parameters into a template (or multiple templates) that you have created, and are waiting for it to consume.  In fact, which template the GP service will use is one of the parameters. We edited the python script a bit for our needs, but it works right out of the box.

The way our application works step by step is as follows:

User opens the application and selects what they want to print.  They use combo boxes or text input boxes (depending which layer they're focusing on) to run a query task that zooms to the feature they want on their map. Once the query is complete and the feature they want to print is on their screen, they select which template they want to use from a separate combo box (for example, we have a map with map elements such as scale bar, locator map, etc, and a plain map without them.) 

After they have everything selected, they press a button called "Export PDF" which is tied to an event handler that does the following:

Sets the PDFTitle variable based on the feature that the query returned (in our app, they do not create their own title, but this is an easy change).
Sets the Mapscale variable based on a map scale equation we use to make the features fit perfectly into the data frame.
Sets theTemplate variable based on which template they have selected from the combobox.
Passes these variables, and all the other arguments they require, to the parameters.
Creates the Geoprocessor ExportTask.
Executes the ExportTask.SubmitJobAsync

Then under the ExportTask.JobCompleted event handler, we:

Set our image.visibility = Visibility.Visible (the little PDF image they click to get their map)
Set our pdfURL = the url of the PDF that was created (you can change the output location in the python script)

Then we have a PDF image mouseleftbuttondown event handler, and when clicked we:

HtmlPage.Window.Invoke("PDFs", pdfURL);

And the map that was created is opened in a browser window and can be saved, printed, etc.

Phew.  I hope that helped in some way, like I said if you need more code samples I'll look into getting those available.
0 Kudos
JayKappy
Occasional Contributor
I thank you for your time and support....I guess I am confused on the service/script...its says there are instructions to publish the service on the server but I dont see any...

From the link Patrick posted above, we got the Python script that ESRI staff developed for doing a print with Arcpy.mapping. The python script gets published in ArcServer as a geoprocessing service. I'm sure you know all this already, but I'm starting from the beginning. This geoprocessing service accepts a series of parameters that are passed to it, and then passes these parameters into a template (or multiple templates) that you have created, and are waiting for it to consume. In fact, which template the GP service will use is one of the parameters. We edited the python script a bit for our needs, but it works right out of the box.

Is this the series of CS pages he posted?  Strike that ....I was referencign another entry in this forum....I see the files he gave in the GP folder....Trying to figure out how these are published.....right now I am running this application off my local drive.  The only part that i am hitting server on is for the map services, and that is done by another that supplies us with the map services etc.  How would i have them install this service?  This is all very new to me as well....

So I assume that the majority of the code you posted is about all you need on your side...the rest is a service published on the server side?  that correct?
I think I need to get the service workign first....then shold just have to use yoru code to call the service...
Again I thank you very much for this.....
0 Kudos
JayKappy
Occasional Contributor
Foudn the directions.....trying to start with the server side pyton....

Export Map to PDF using arcpy.mapping
Written by David Spriggs dspriggs@esri.com

Setup:
GP and Map Service:
1. Unzip all zip files and move the contents of the GP -> ExportPDF folder to your ArcGIS server.
2. Publish the ExportPDF toolbox.
3. Publish the SaveTheBAy.mxd found in the Map Service folder.
4. Clear REST cache if needed.

Not sure why I need to have an mxd published....assume that I can use the current map service I am already using?????

THanks so much for helping me strighten this out and learning...
0 Kudos
JonathanHouck
New Contributor III
To publish the geoprocessing service you just set the script up in an ArcGIS toolbox like you would any other python script (don't forget to set the parameters).  Then you right click on the toolbox and publish to ArcGIS Server.  You'll see it in the list with all your map services, except it will have a toolbox icon.
0 Kudos
JayKappy
Occasional Contributor
OK so if that is published...then all I need to do is use yoru few lines of code to push the parameters to the service?  That correct?
Thanks
0 Kudos
JonathanHouck
New Contributor III
As long as you get the job parameters set correctly I don't think I'm missing anything.  Keep in mind the samples I posted are in C#, I haven't used VB.net which I believe you initially inquired about.
0 Kudos
JayKappy
Occasional Contributor
To publish the geoprocessing service you just set the script up in an ArcGIS toolbox like you would any other python script (don't forget to set the parameters). Then you right click on the toolbox and publish to ArcGIS Server. You'll see it in the list with all your map services, except it will have a toolbox icon.

Yea I did the conversion..pretty stright forward....

1. I added the python to my ArcToolbox by right clicking ArcToolbox and selecting "Add Toolbox"
2. I then choose the toolbox that was supplied above.

Everything seems to be there XY min max, Layout etc etc etc...

What parameters are you speaking of?
I thought thats what the code does....passing the parameters in that is

I really thank you for your patience...I know I am making a mountain out of an ant hill here.

After I get this on the server I can focus on getting the corect files on my web root (making sure to modify the .js page for the proxies etc)....then should just need your few lines of code and I shoudl be running....knock on wood.
0 Kudos