[MapActionFilter] [HttpPost] [ValidateInput(false)] public string MapPrint(Map map, GeoCollection args) { PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas(); PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); XGraphics graphics = XGraphics.FromPdfPage(page); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XFont font = new XFont("Roboto", 15, XFontStyle.Regular, options); string pagesize = args["size"].ToString(); string orientation = args["orientation"].ToString(); if (pagesize == "A0") { page.Size = PageSize.A0; } if (pagesize == "A1") { page.Size = PageSize.A1; } if (pagesize == "A2") { page.Size = PageSize.A2; } if (pagesize == "A3") { page.Size = PageSize.A3; } if (pagesize == "A4") { page.Size = PageSize.A4; } if (orientation == "Landscape") { page.Orientation = PageOrientation.Landscape; } if (orientation == "Portrait") { page.Orientation = PageOrientation.Portrait; } // page.Orientation = PageOrientation.Portrait; // page.Size = PageSize.A3; //string font = "Roboto"; string Area = ""; List lstlayeroverlay = new List(); List lstlegend = new List(); lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays["LayersOverlay"]); lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays["ShapeOverlay"]); List lstadornmentoverlay = new List(); lstadornmentoverlay.Add(map.AdornmentOverlay); double area = shapeArea; int headerHeight = 70; string title = args["title"].ToString(); string subTitle = args["subtitle"].ToString(); string legend = args["legend"].ToString(); int currentzoomlevel = Convert.ToInt32(args["currzoomLevel"]); string Shapearea = args["areavalue"].ToString(); if (legend != "undefined") { lstlegend = (new JavaScriptSerializer()).Deserialize>(args["legend"].ToString()); } try { XRect labelRect = new XRect(80, 5, page.Width -100 , (int)headerHeight / 2); graphics.DrawRectangle(Brushes.White, new Rectangle(0, 0, (int)page.Width, (int)headerHeight)); graphics.DrawLine(new XPen(XColor.FromKnownColor(KnownColor.Black), 1), 0, (int)headerHeight + 2, (int)page.Width, (int)headerHeight + 1); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/Logo_EMIS.jpg")), new XRect(10, 20, headerHeight + 40, headerHeight - 40)); graphics.DrawString("Number Of Student Completing Last Grade Of a Stage ; Number Of Student Completing Last Grade Of a Stage", new XFont("Roboto", 12, XFontStyle.Bold), XBrushes.Black, labelRect, XStringFormats.Center); graphics.DrawString("Number Of Student Completing Last Grade Of a Stage ", new XFont("Roboto", 10, XFontStyle.Bold), XBrushes.Black, new XRect(80, (int)headerHeight / 3, page.Width - 100, (int)headerHeight / 3), XStringFormats.Center); //graphics.DrawString(title, new XFont("Roboto", 20, XFontStyle.Bold), XBrushes.Black, new XRect(0, 5, page.Width, (int)headerHeight / 3), XStringFormats.Center); //graphics.DrawString(subTitle, new XFont("Roboto", 16, XFontStyle.Bold), XBrushes.Black, new XRect(0, (int)headerHeight / 3, page.Width, (int)headerHeight / 3), XStringFormats.Center); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/MoE-logo.png")), new XRect(page.Width - headerHeight + 15, 8, headerHeight - 20, headerHeight - 20)); } finally { graphics.Dispose(); } int FooterHeight = 80; int margin = 5; headerHeight = headerHeight + 2 + margin; int MapHeight = Convert.ToInt32(page.Height - (headerHeight + FooterHeight)); pdfGeoCanvas.DrawingArea = new Rectangle(0, headerHeight, (int)page.Width, MapHeight); Collection labelsInLayers = new Collection(); RectangleShape rect = new RectangleShape(double.Parse(args["left"].ToString()), double.Parse(args["top"].ToString()), double.Parse(args["right"].ToString()), double.Parse(args["bottom"].ToString())); foreach (LayerOverlay layeroverlay in lstlayeroverlay) { foreach (Layer layer in layeroverlay.Layers) { layer.Open(); pdfGeoCanvas.BeginDrawing(page, rect, map.MapUnit); layer.Draw(pdfGeoCanvas, labelsInLayers); layer.Close(); pdfGeoCanvas.EndDrawing(); } } //List lstmarkeroverlay = new List(); //lstmarkeroverlay.Add((InMemoryMarkerOverlay)map.CustomOverlays["Female"]); //lstmarkeroverlay.Add((InMemoryMarkerOverlay)map.CustomOverlays["Male"]); //lstmarkeroverlay.Add((InMemoryMarkerOverlay)map.CustomOverlays["Mix"]); //if (lstmarkeroverlay[0].FeatureSource.InternalFeatures.Count > 0 || lstmarkeroverlay[1].FeatureSource.InternalFeatures.Count > 0 || // lstmarkeroverlay[2].FeatureSource.InternalFeatures.Count > 0) //{ if (map.CustomOverlays.Where(x => x.Name == "Female" || x.Name == "Male" || x.Name == "Mix").Count() > 0) { List lstmarkeroverlay = new List(); lstmarkeroverlay.Add((InMemoryMarkerOverlay)map.CustomOverlays["Female"]); lstmarkeroverlay.Add((InMemoryMarkerOverlay)map.CustomOverlays["Male"]); lstmarkeroverlay.Add((InMemoryMarkerOverlay)map.CustomOverlays["Mix"]); if (currentzoomlevel >= 10) { List markerLayers = ConvertInMemoryMarkerOverlayToInMemoryFeatureLayer(lstmarkeroverlay, map); foreach (InMemoryFeatureLayer layer in markerLayers) { layer.Open(); pdfGeoCanvas.BeginDrawing(page, rect, map.MapUnit); layer.Draw(pdfGeoCanvas, labelsInLayers); layer.Close(); pdfGeoCanvas.EndDrawing(); } } } foreach (AdornmentOverlay adornmentoverlay in lstadornmentoverlay) { foreach (Layer layer in adornmentoverlay.Layers) { layer.Open(); pdfGeoCanvas.BeginDrawing(page, rect, map.MapUnit); layer.Draw(pdfGeoCanvas, labelsInLayers); layer.Close(); pdfGeoCanvas.EndDrawing(); } } if (hasRights("ShowSchoolLegend", false)) { string language = settings.getLayerLanguage().ToString(); try { //Code For School Legend if (language == "Dari") { graphics = XGraphics.FromPdfPage(page); //double XPosImage = page.Width - 150; //double XPosLabel = page.Width - 135; double XPosImage = page.Width - 120; double XPosLabel = page.Width - 105; double XPosBMFImageNLabel = page.Width - 160; graphics.DrawString("School Stage", new XFont("Arial", 12), XBrushes.Black, new XRect(XPosLabel - 15, page.Height - FooterHeight - 170, 20, 12), XStringFormats.TopLeft); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/1. A.png")), new XRect(XPosImage, page.Height - FooterHeight - 156, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/2. M.png")), new XRect(XPosImage, page.Height - FooterHeight - 144, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/3. L.png")), new XRect(XPosImage, page.Height - FooterHeight - 132, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/4. SH.png")), new XRect(XPosImage, page.Height - FooterHeight - 120, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/5. DM.png")), new XRect(XPosImage, page.Height - FooterHeight - 108, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/6. TA.png")), new XRect(XPosImage, page.Height - FooterHeight - 96, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/7. TN.png")), new XRect(XPosImage, page.Height - FooterHeight - 84, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/8. DA.png")), new XRect(XPosImage, page.Height - FooterHeight - 72, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/9. DH.png")), new XRect(XPosImage, page.Height - FooterHeight - 60, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/10. MA.png")), new XRect(XPosImage, page.Height - FooterHeight - 48, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/dari/11. MS.png")), new XRect(XPosImage, page.Height - FooterHeight - 36, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/pointers/both.png")), new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 112, 15, 15)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/pointers/female.png")), new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 87, 15, 15)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/pointers/male.png")), new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 62, 15, 15)); graphics.DrawString("Both", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 96, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Female", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 71, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Male", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 47, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Primary School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 156, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Secondary School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 144, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Upper Secondary School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 132, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Shpe Lysa", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 120, 20, 12), XStringFormats.TopLeft); graphics.DrawString("TTC", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 108, 20, 12), XStringFormats.TopLeft); graphics.DrawString("TVET Institute", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 96, 20, 12), XStringFormats.TopLeft); graphics.DrawString("TVET School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 84, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Darol Ulom", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 72, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Darol Hefaz", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 60, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Madrassa", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 48, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Literacy School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 36, 20, 12), XStringFormats.TopLeft); } else if (language == "English") { graphics = XGraphics.FromPdfPage(page); //double XPosImage = page.Width - 150; //double XPosLabel = page.Width - 135; double XPosImage = page.Width - 120; double XPosLabel = page.Width - 105; double XPosBMFImageNLabel = page.Width - 160; graphics.DrawString("School Stage", new XFont("Arial", 12), XBrushes.Black, new XRect(XPosLabel - 15, page.Height - FooterHeight - 170, 20, 12), XStringFormats.TopLeft); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/1. A.png")), new XRect(XPosImage, page.Height - FooterHeight - 156, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/2. M.png")), new XRect(XPosImage, page.Height - FooterHeight - 144, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/3. L.png")), new XRect(XPosImage, page.Height - FooterHeight - 132, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/4. SH.png")), new XRect(XPosImage, page.Height - FooterHeight - 120, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/5. DM.png")), new XRect(XPosImage, page.Height - FooterHeight - 108, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/6. TA.png")), new XRect(XPosImage, page.Height - FooterHeight - 96, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/7. TN.png")), new XRect(XPosImage, page.Height - FooterHeight - 84, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/8. DA.png")), new XRect(XPosImage, page.Height - FooterHeight - 72, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/9. DH.png")), new XRect(XPosImage, page.Height - FooterHeight - 60, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/10. MA.png")), new XRect(XPosImage, page.Height - FooterHeight - 48, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/english/11. MS.png")), new XRect(XPosImage, page.Height - FooterHeight - 36, 12, 12)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/pointers/both.png")), new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 112, 15, 15)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/pointers/female.png")), new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 87, 15, 15)); graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/pointers/pointers/male.png")), new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 62, 15, 15)); graphics.DrawString("Both", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 96, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Female", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 71, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Male", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosBMFImageNLabel, page.Height - FooterHeight - 47, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Primary School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 156, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Secondary School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 144, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Upper Secondary School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 132, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Shpe Lysa", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 120, 20, 12), XStringFormats.TopLeft); graphics.DrawString("TTC", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 108, 20, 12), XStringFormats.TopLeft); graphics.DrawString("TVET Institute", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 96, 20, 12), XStringFormats.TopLeft); graphics.DrawString("TVET School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 84, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Darol Ulom", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 72, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Darol Hefaz", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 60, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Madrassa", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 48, 20, 12), XStringFormats.TopLeft); graphics.DrawString("Literacy School", new XFont("Arial", 7.5), XBrushes.Black, new XRect(XPosLabel, page.Height - FooterHeight - 36, 20, 12), XStringFormats.TopLeft); //PdfSharp.Drawing.Layout.XTextFormatter tf = new PdfSharp.Drawing.Layout.XTextFormatter(graphics); //tf.Alignment = PdfSharp.Drawing.Layout.XParagraphAlignment.Center; ////tf.DrawString("", font, XBrushes.Black, 18, new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft); //tf.DrawString("کنر" + "Kunar", font, XBrushes.Black, new XRect(XPosLabel, headerHeight + MapHeight + 4, 20, 12), XStringFormats.TopLeft); } } finally { graphics.Dispose(); } } if (Shapearea != "") { try { Area = Shapearea; // int Xpos = Convert.ToInt32(page.Width - 160); int Ypos = headerHeight + MapHeight + 5; graphics = XGraphics.FromPdfPage(page); Rectangle shapeRect = new Rectangle(20, Ypos, 150, 20); graphics.DrawRectangle(new SolidBrush(ColorTranslator.FromHtml("#3F4B5B")), Rectangle.Round(shapeRect)); graphics.DrawString("Value: " + Area, new XFont("Roboto", 10, XFontStyle.Regular), XBrushes.White, shapeRect, XStringFormats.TopCenter); } finally { graphics.Dispose(); } } try { graphics = XGraphics.FromPdfPage(page); double xpos = page.Width - 200; int ypos = headerHeight + MapHeight - 30; graphics.DrawImage(XImage.FromFile(Server.MapPath("~/images/narrow.png")), new XRect(xpos, ypos, 17, 17)); } finally { graphics.Dispose(); } int Hfooter = headerHeight + MapHeight; int Hmap = headerHeight + FooterHeight; int YFooter = headerHeight + MapHeight + 2; //int counter = 12; int counter = 15; if (legend != "undefined") { try { graphics = XGraphics.FromPdfPage(page); graphics.DrawString("LEGEND", new XFont("Roboto", 10, XFontStyle.Regular), XBrushes.Black, new XRect(page.Width - 80, MapHeight + headerHeight, 17, 15), XStringFormats.TopLeft); } finally { graphics.Dispose(); } foreach (var data in lstlegend) { try { graphics = XGraphics.FromPdfPage(page); double rectX = page.Width / 5; graphics.DrawRectangle(new SolidBrush(ColorTranslator.FromHtml(data.Color)), new XRect(page.Width - 80, MapHeight + headerHeight + counter, 8, 8)); //////////to make boundaries fo the rows //graphics.DrawRectangle(new XPen(XColor.FromKnownColor(KnownColor.Black), .5), new XRect(rectX - 12, YFooter + counter-2, 100, 27)); graphics.DrawString(data.Start.ToString() + " - " + data.End.ToString(), new XFont("Roboto", 7, XFontStyle.Regular), XBrushes.Black, new XRect(page.Width - 70, MapHeight + headerHeight + counter, 17, 15), XStringFormats.TopLeft); ////////////to display in line increase the counter value to 60 counter = counter + 10; } finally { graphics.Dispose(); } } } try { // int Xpos = Convert.ToInt32(page.Width /4); int Ypos = Convert.ToInt32(page.Height - 12); graphics = XGraphics.FromPdfPage(page); graphics.DrawString("DATASOURCES (EMIS, Literacy, CSO and AGCHO) COPYRIGHT2016-17. ALL RIGHTS RESERVED Maintained & Developed By Beyond Solutions Private Limited", new XFont("Roboto", 6), XBrushes.Black, new XRect(10, Ypos, 20, 12), XStringFormats.TopLeft); } finally { graphics.Dispose(); } string filepath = "~/Content/FTP/PrintDocument/" + "MapSuitePDFMap_" + DateTime.Now.Ticks + ".pdf"; document.Save(Server.MapPath(filepath)); return VirtualPathUtility.ToAbsolute(filepath); } private List ConvertInMemoryMarkerOverlayToInMemoryFeatureLayer(List lstmarkeroverlay) { List markerLayers = new List(); foreach (InMemoryMarkerOverlay markeroverlay in lstmarkeroverlay) { // Chooses images according to markeroverlay name. //string imagePath = Server.MapPath("/images/mixpin.png"); string imagePath = ""; if (markeroverlay.Name == "Male") { imagePath = Server.MapPath("/images/boyspin_print.png"); } if (markeroverlay.Name == "Female") { imagePath = Server.MapPath("/images/girlspin_print.png"); } if (markeroverlay.Name == "Mix") { imagePath = Server.MapPath("/images/mixpin_print.png"); } // Creates pointStyle to shows marker as image. PointStyle pointStyle = new PointStyle(); pointStyle.Image = new GeoImage(imagePath); //pointStyle.Image = new GeoImage(10, 10); pointStyle.PointType = PointType.Bitmap; // Let the anchor in the image match the position in the map through the offset pointStyle.XOffsetInPixel = -10.5f; pointStyle.YOffsetInPixel = -25f; InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = pointStyle; inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; // Add feature into inMemoryFeatureLayer. foreach (Feature markerFeature in markeroverlay.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns)) { inMemoryFeatureLayer.InternalFeatures.Add(markerFeature); } markerLayers.Add(inMemoryFeatureLayer); } return markerLayers; }