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"))); WorldMapKitLayer worldmap = new WorldMapKitLayer(); worldmap.Open(); worldmap.Projection = WorldMapKitProjection.SphericalMercator; map.StaticOverlay.Layers.Add(worldmap); 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(); 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.Meter); 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); } } }