Showing posts with label ArcGIS Server. Show all posts
Showing posts with label ArcGIS Server. Show all posts

Wednesday, November 24, 2010

ESRI Print to PDF Task Sample for ArcGIS Server 9.3.1 - Part of the Thanksgiving Code Buffet

]If you have been following along, then you know this weekend I am hosting a Thanksgiving code buffet. Perhaps you don't want to miss out on these knowledge dishes when they are fresh because you have to shop. Don't worry, I posted Black Friday Specials and gift cards right here for you. And I had to shop around for ones that I thought you may like. But, if you don't want anything to do with that online shopping stuff; I took care of that too. Content is at the very top, bottom and on the sides. There are a few gadgets I will share with you in my posts. They are expensive, so I don't expect you to buy them, but if you do; I hope you share. We can jsut have fun talking about them.

Now for the other PrintTask for the Web ADF. I have referred to this as the main course; it is our turkey. But, I will do the best I can to make it tasty.

I read this post http://www.arcgisserverblog.com/2008/12/print-map-with-arcgis-server.html and decided to do the same thing that I do when I buy a new pc; take it apart and change it. In this example, we are going to export the image of the map, obtain the name of the new image file and then perform a page redirect from there just like in the ESRI JSAPI 2.1 Print to PDF example.

 The screen print I planned to share with you is not available right now, but I do have a screen print of the MapResourceManager. With the main course like this, what does that say about my side dishes?

To define your map, we don't use the REST API in this example, so set you MapResource Manager as displayed in the image below.


It is the same resource. We are just not using the REST API in this one. Now for the one thing that separates these two examples; the code.

The following is plain text, but this way you can copy it for your own application. You do need a license for ESRI ArcGIS Server to use this code. Nothing to worry about; there will be plenty of other map examples that will cost you nothing to use. But if you are unable to move away from the Web ADF right now, then this you may find this code helpful for two reasons. The first is that you will be able print to pdf and the second is that the page that you redirect to, that creates the pdf is the exact same page. So, you can migrate this PrintTask to the JSAPI 2.1 if that is your API of choice. If not, you may be interested in another such as Silverlight or Flex. We aren't serving those this weekend. But if you want to bring a code plate and serve one of those up, let me know. I will link to it as this will free up time for me to share additional code sooner.

Here is your export function for exporting your image:

Public Shared Function ExportMapImage(ByVal ADFMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map, ByVal OutputPath As String) As String


Dim bitmaps As New System.Collections.Generic.List(Of System.Drawing.Image)()

For Each mf As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality In ADFMap.GetFunctionalities()

If mf IsNot Nothing Then

Dim mapImage As ESRI.ArcGIS.ADF.Web.MapImage = mf.DrawExtent(ADFMap.Extent)



mapImage = mf.DrawExtent(ADFMap.Extent)

If mapImage Is Nothing Then

Continue For

End If

If mapImage.GetImage() IsNot Nothing Then

bitmaps.Add(mapImage.GetImage())

End If

End If

Next



Dim newImg As New System.Drawing.Bitmap(Convert.ToInt16(ADFMap.Width.Value), Convert.ToInt16(ADFMap.Height.Value))



Dim imgGraphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(newImg)

Dim i As Integer = bitmaps.Count - 1

While i >= 0

imgGraphics.DrawImage(bitmaps(i), 0, 0, Convert.ToInt16(ADFMap.Width.Value), Convert.ToInt16(ADFMap.Height.Value))

i += -1

End While

Dim Ticks As Long = DateTime.Now.Ticks

Dim ImagePath As String = OutputPath & "mapimage" & Ticks & ".png"



newImg.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Png)



Return "mapimage" & Ticks & ".png"

End Function
 
 
Once you export your image, you need call the above function. We are going to use a button click event.
 
Protected Sub btnPrintMap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintMap.Click


'The following is how you should write out the path variables

'TextBox1.Text = "http://YourWebSite/Images/" & ExportMapImage(Map1, "http:///YourWebSite/Images/").ToString

Response.Redirect("PrintTaskResults.aspx?sender=" + TextBox1.Text.ToString)



End Sub
 
Although we are redirecting to another page, the embedded pdf page has something that you did not see in the last in the JSAPI 2.1. An image is created, but once the pdf is created, we have the code delete the image. So, here is the Page_Load event. 



In this line we create our pdf and add the image.



Since the image has been used for the pdf and it does not contain a unique name, we don't want our Images folder to constantly grow, so we check to see the image file used in the pdf still exists. If it does, it is deleted. In this way we have automated the clean up of our Images folder.


That concludes this sample, so now feel free to download the Print to PDF in ESRI ArcGIS Server 9.3.1 using the Web ADF in .NET now.

Monday, September 6, 2010

GIS - Removing The Barriers Of Geography To Open The Corridors Of Knowledge

With ESRI, hosting Dev Meet Ups across the country, I wanted to share why these little events are huge opportunities. An invaluable resource that any developer can acquire is connecting with knowledgeable developers in their field. Unfortunately, there are usually barriers that prevent some developers from accessing them. But even the developers that have access to what is needed to attend events, there is another roadblock that must be addressed. Which events are the best? What event will help me grow in my field and meet others that would be of value to my gowth? There are many questions that can be asked, but the point is; nobody can go to everything and travelling can have a negative impact on the time for which anyone has to gain knowledge.

Now, we have ESRI Dev Meet Ups for the first time, and for many a barrier of meeting fellow developers and ESRI staff has been removed. Don't be too quick to dismiss such an opportunity as something that may not pertain to you or your organization as some of the good things that can be taken away from events never has been, never is, and never will be advertised. Here are a few.

I have had the opportunity to meet the founder and President of ESRI, Jack Dangermond while taking Developing ArcGIS Server Applications with the Web ADF. If you want to know how I got that chance; I will tell you my secret. I walked up to him and introduced myself. He was having lunch with someone at the campus cafeteria, but I enjoy GIS so much that this was not going to  be an excuse not to meet Jack. I am glad to have had the opportunity to meet him and I know from reputation and experience that the GIS community is very important to Jack and what we have to say. If you have the opportunity to meet him; I encourage it.

My Developing ArcGIS Server Applications with the Web ADF in .NET was taught by Rob Burke, the author of Getting to Know ArcObjects: Programming ArcObjects with VBA. He was helpful during training as well as away and I hope that you get the chance to take one of his classes as well. His presentation and knowledge add quality to the course content that can not be purchased.

During the same time period, I went to the DevSummit and met Jim Barry, ESRI EDN Manager. Well, I introduced myself to him to. I had plenty of questions and ideas. He is very interested in listening to what the developer community has to say and meeting their needs as a whole while the individual is also important, they don't take precedence over the community. And Jim will be at most of the Meet Ups. This alone is an excellent reason for all developers that can; to attend a Meet Up in their area. If you have ideas bring them and talk to Jim about them. If there is something that frustrates you or is just a concern as a developer, don't complain to the world, communicate with Jim and your fellow developers at the Meet Up.

I want to thank the City of Decatur for the opportunities that I have had for training, conferences, and other GIS events of which I have had the chance to attend. Because of these opportunities, this is the third year in a row that I have been formally recognized in the field of GIS.

In 2008,  I was the Grand Prize Winner of the ArcGIS 9.3 Release Candidate Incentive Program which allowed for me to donate the prize, an annual EDN subscription saving the city over $1,000 so that they would not need to purchase the software that I used for development.

In 2009, I was published in GIS Notes and online magazine produced by ILGISA, who is having their fall conference next month on October 20-21 2010.

And this year, ESRI asked me to provide a keynote for developers migrating from the Web ADF, an API that is being deprecated by ESRI. I will talk about migrating to the JavaScript API 2.0 and integrating JavaScript libraries, but I have developed in Silverlight as well.

I will be covering new areas that you will not see on ESRI's website including separating content, presentation, and functionality; unobtrusive JavaScript to allow for development in multiple JavaScript libraries and learn how to make the ScriptManager work with the JSAPI so you can use the AJAX Control Toolkit in the .NET Framework 4.0. In addition, I Beta tested Visual Studio 2010.

Finally, I will be sharing a new custom tool that I have created. You may have or might be using this tool, at this time, but the one I will be sharing  will remove complexity be more powerful than many like it. It will be for both C# and VB.NET in Silverlight and the JSAPI 2.0.

Don't forget while you may have started developing in these new API's, this is a good time to make a connection with developers that work in the API of your choice, allowing you to connect after the Meet Up is over when your application appears to be disconnected or simply breaks and it will.

Want to know what the new tool that I spoke about is? I plan on sharing it exclusively at the ESRI Dev Meet Up in Decatur, Illinois on September 16th! So register now and get the word out.Tweet that!

Talk to you real soon. Or do you want to hear more? If you do, check out Part II and learn about how and why the Web Dev Network was created, and why it even surprised me.

Chris

Sunday, September 5, 2010

Novice To Network Update

The Novice To Network series will have to wait as it would be a little too much content to write about in such a short time before the Dev Meet Up; so there will be a short two part post which will be titled; GIS - Removing The Barriers Of Geography To Open The Corridors Of Knowledge.

Part I is already written and it will be about the Dev Meet Up itself. I'm just tired. But I want to make sure that it still looks good after a good night's sleep.

 Part II will be about the Web Dev Network as I plan on demonstrating how both are related in providing connectivity to the community.

Talk to you soon.

Chris