xMin = arcpy.GetParameterAsText(0) if xMin == '#' or not xMin: Â Â Â xMin = "4357197" # provide a default value if unspecified yMin = arcpy.GetParameterAsText(1) if yMin == '#' or not yMin: Â Â Â yMin = "1414133" # provide a default value if unspecified xMax = arcpy.GetParameterAsText(2) if xMax == '#' or not xMax: Â Â Â xMax = "4357210" # provide a default value if unspecified yMax = arcpy.GetParameterAsText(3) if yMax == '#' or not yMax: Â Â Â yMax = "1414160" # provide a default value if unspecified
patrickbrooke ANY help on how to integrate that into a Silverlight app that is using VB. This forum entry has confused me even more as I am seeign a few different ways to do it...I love the option to choose a map title etc... Can you help by informing how to incorporate into silverlight? Thanks
List<GPParameter> jobParameters = new List<GPParameter>(); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPDouble("xMin", boundingExtent.XMin)); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPDouble("yMin", boundingExtent.YMin)); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPDouble("xMax", boundingExtent.XMax)); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPDouble("yMax", boundingExtent.YMax)); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPString("Spatial_Reference", MyMap.SpatialReference.WKID.ToString())); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPDouble("Map_Scale", Mapscale)); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPString("Visiblelayers", "None")); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPString("Layout", theTemplate)); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPBoolean("Include_Attributes", false)); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPString("Map_Title", pdfTitle)); Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPString("PointGraphics", ""));Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â jobParameters.Add(new GPString("PolyGraphics", ""));
Geoprocessor ExportTask = new Geoprocessor("http://......../rest/services/ExportPDF_GP/GPServer/ExportToPDF"); Â Â Â Â Â Â Â Â Â Â Â ExportTask.JobCompleted += new EventHandler<JobInfoEventArgs>(ExportTask_JobCompleted); Â Â Â Â Â Â Â Â Â Â Â ExportTask.Failed += new EventHandler<TaskFailedEventArgs>(ExportTask_Failed); Â Â Â Â Â Â Â Â Â Â Â ExportTask.SubmitJobAsync(jobParameters);
This is the best way to create a pdf with a silverlight GIS web application. We have modified this sample to work in our environment with much success.http://www.arcgis.com/home/item.html?id=8f16fdeef39c46b3952002b2d85ea5deThe maps produced, since you print to pdf from the source data, are high quality, not the 96 dpi ones you get from REST.
using PdfSharp.Pdf; Â Â Â Â Â Â Â private void PDFbutton_MouseLeftButtonUp(object sender, MouseEventArgs e) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â SaveFileDialog savePDF = new SaveFileDialog(); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â savePDF.Filter = "PDF file format|*.pdf"; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â savePDF.DefaultExt = ".pdf"; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (savePDF.ShowDialog() == true) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â System.IO.Stream PDFstream = savePDF.OpenFile(); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PDFExporter PDFNew = new PDFExporter(); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PDFNew.SetMap(myMap); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PDFNew.SetOutputStream(PDFstream); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PDFNew.DoExport(); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â }
   Private Sub Print_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)        Dim savePDF As New SaveFileDialog()        savePDF.Filter = "PDF file format|*.pdf"        savePDF.DefaultExt = ".pdf"        If savePDF.ShowDialog() = True Then            Dim PDFstream As System.IO.Stream = savePDF.OpenFile()            Dim PDFNew As New PDFExporter()                     PDFNew.SetMap(MyMap)            PDFNew.SetOutputStream(PDFstream)            PDFNew.DoExport()        End If    End Sub
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
We ended up going pretty lean on the exporter. The method we implemented is as followsprivate void Map2PDF_Click(object sender, RoutedEventArgs e)        {            /* // Don't need the ExportPDF dialog anymore            CMC_Viewer.Views.ExportPDF map2pdf = new CMC_Viewer.Views.ExportPDF();            map2pdf.SetMap(this.Map);            map2pdf.Show();             * */            // Display save-as dialog            SaveFileDialog dialog = new SaveFileDialog();            dialog.Filter = "PDF|*.pdf";            if (!dialog.ShowDialog().Value)            {                return;            }            // Create a new dynamic layer from the same map service as current tiled layer            ArcGISTiledMapServiceLayer tiled = this.Map.Layers[0] as ArcGISTiledMapServiceLayer;            ArcGISDynamicMapServiceLayer dynamic = new ArcGISDynamicMapServiceLayer()            {                Url = tiled.Url,                ImageFormat = ArcGISDynamicMapServiceLayer.RestImageFormat.JPG            };            // When the dynamic layer has initialized create the in-memory PDF document            dynamic.Initialized += (a, b) =>            {                dynamic.GetUrl(this.Map.Extent,                               (int)this.Map.ActualWidth,                               (int)this.Map.ActualHeight,                               delegate(string url, int width, int height, Envelope extent)                               {                                   // Download a new image of identical to what is currently displayed in the map                                   WebClient webClient = new WebClient();                                   webClient.OpenReadCompleted += (c, f) =>                                   {                                       // Use the dispatcher to force execution in the UI thread                                       Dispatcher.BeginInvoke(delegate()                                       {                                           // Create the PDF document, set document information properties                                           PdfDocument document = new PdfDocument();                                           document.Info.Title = "Map";                                           // Create a new page with the same dimensions as the browser map                                           PdfPage page = new PdfPage(document)                                           {                                               Height = new XUnit(this.Map.ActualHeight, XGraphicsUnit.Presentation),                                               Width = new XUnit(this.Map.ActualWidth, XGraphicsUnit.Presentation)                                           };                                           document.Pages.Add(page);                                           // Create a graphics object for writing to the page                                           XGraphics graphics = XGraphics.FromPdfPage(page);                                           // Add the map image to the page                                           XImage image = XImage.FromStream(f.Result);                                           graphics.DrawImage(image, 0d, 0d);                                           // Save the PDF document to the user specified filename                                           document.Save(dialog.OpenFile());                                           // Notify the user that we're done                                           MessageBox.Show("Map saved to '" + dialog.SafeFileName + "'");                                       });                                   };                                   webClient.OpenReadAsync(new Uri(url));                               });            };            dynamic.Initialize();        }We found that the size of the map to be exported has to be set better than in other examples. Anyway, the code above produces a high quality map.
private void Map2PDF_Click(object sender, RoutedEventArgs e)        {            /* // Don't need the ExportPDF dialog anymore            CMC_Viewer.Views.ExportPDF map2pdf = new CMC_Viewer.Views.ExportPDF();            map2pdf.SetMap(this.Map);            map2pdf.Show();             * */            // Display save-as dialog            SaveFileDialog dialog = new SaveFileDialog();            dialog.Filter = "PDF|*.pdf";            if (!dialog.ShowDialog().Value)            {                return;            }            // Create a new dynamic layer from the same map service as current tiled layer            ArcGISTiledMapServiceLayer tiled = this.Map.Layers[0] as ArcGISTiledMapServiceLayer;            ArcGISDynamicMapServiceLayer dynamic = new ArcGISDynamicMapServiceLayer()            {                Url = tiled.Url,                ImageFormat = ArcGISDynamicMapServiceLayer.RestImageFormat.JPG            };            // When the dynamic layer has initialized create the in-memory PDF document            dynamic.Initialized += (a, b) =>            {                dynamic.GetUrl(this.Map.Extent,                               (int)this.Map.ActualWidth,                               (int)this.Map.ActualHeight,                               delegate(string url, int width, int height, Envelope extent)                               {                                   // Download a new image of identical to what is currently displayed in the map                                   WebClient webClient = new WebClient();                                   webClient.OpenReadCompleted += (c, f) =>                                   {                                       // Use the dispatcher to force execution in the UI thread                                       Dispatcher.BeginInvoke(delegate()                                       {                                           // Create the PDF document, set document information properties                                           PdfDocument document = new PdfDocument();                                           document.Info.Title = "Map";                                           // Create a new page with the same dimensions as the browser map                                           PdfPage page = new PdfPage(document)                                           {                                               Height = new XUnit(this.Map.ActualHeight, XGraphicsUnit.Presentation),                                               Width = new XUnit(this.Map.ActualWidth, XGraphicsUnit.Presentation)                                           };                                           document.Pages.Add(page);                                           // Create a graphics object for writing to the page                                           XGraphics graphics = XGraphics.FromPdfPage(page);                                           // Add the map image to the page                                           XImage image = XImage.FromStream(f.Result);                                           graphics.DrawImage(image, 0d, 0d);                                           // Save the PDF document to the user specified filename                                           document.Save(dialog.OpenFile());                                           // Notify the user that we're done                                           MessageBox.Show("Map saved to '" + dialog.SafeFileName + "'");                                       });                                   };                                   webClient.OpenReadAsync(new Uri(url));                               });            };            dynamic.Initialize();        }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.