Can antbody provide me some quick idea on this. I am using the following lines of code to export only the BaseMap to PDF Document. Need to export with Map graphics and the legend toolbar.
private void btnOK_Click(object sender, RoutedEventArgs e)
{
// Display save-as dialog
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "PDF|*.pdf |JPEG Files (*.jpeg)|*.jpeg";
if (dialog.ShowDialog() == true)
{
// return;
//}
// Create a new dynamic layer from the same map service as current tiled layer
ArcGISTiledMapServiceLayer tiled = new ArcGISTiledMapServiceLayer();
tiled = this.TheMap.Layers["MyLayer"] 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.TheMap.Extent,
(int)this.TheMap.ActualWidth,
(int)this.TheMap.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.TheMap.ActualHeight, XGraphicsUnit.Presentation),
Width = new XUnit(this.TheMap.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();
}
}
Thanks in advance.
~Saurabh.