using System.Collections.ObjectModel; using System.Web; using System.Web.Mvc; using PdfSharp; using PdfSharp.Pdf; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.MvcEdition; using System.Drawing; namespace CSharp_HowDoISamples { public partial class MiscellaneousController : Controller { // // GET: /UsePdfExtension/ public ActionResult UsePdfExtension() { Map map = new Map("Map1", new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage)); map.MapUnit = GeographyUnit.Meter; map.CurrentExtent = new RectangleShape(-10000000, 10000000, 10000000, -10000000); map.MapBackground = new BackgroundLayer(new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"))); map.StaticOverlay.Layers.Add(new OpenStreetMapLayer()); SimpleMarkerOverlay markerOV = new SimpleMarkerOverlay(); Marker marker = new Marker(-8922952.93266, 2984101.58384); marker.WebImage = new WebImage("../content/theme/default/img/marker_blue.gif"); markerOV.Markers.Add(marker); map.CustomOverlays.Add(markerOV); return View(map); } [MapActionFilter] public string ToPdf(Map map, GeoCollection args) { PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); string selectedItemText = args[0].ToString(); if (selectedItemText == "Landscape") { page.Orientation = PageOrientation.Landscape; } PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas(); Bitmap bitmap = map.GetBitmap(); bitmap.Save(@"c:\temp\marker.png"); RectangleShape rect = new RectangleShape(double.Parse(args["left"].ToString()), double.Parse(args["top"].ToString()), double.Parse(args["right"].ToString()), double.Parse(args["bottom"].ToString())); Collection labelsInLayers = new Collection(); foreach (Layer layer in map.StaticOverlay.Layers) { pdfGeoCanvas.BeginDrawing(page, rect, GeographyUnit.DecimalDegree); layer.Open(); layer.Draw(pdfGeoCanvas, labelsInLayers); layer.Close(); pdfGeoCanvas.EndDrawing(); } string relativePath = string.Format("~/Controllers/{0}/{1}", ControllerContext.RouteData.Values["Controller"], "MapSuite PDF Map.pdf"); string filename = Server.MapPath(relativePath); document.Save(filename); return VirtualPathUtility.ToAbsolute(relativePath); } } }