ThinkGeo.com    |     Documentation    |     Premium Support

Not able to print labels for province

Hi ,



  I am using Print PDF map.

 

  My files are  : Normal _map.png(Normal Map View ),MapPDF.png(Print pdf of Normal map view) 





 My problem is i am not able to print labels for province (like Hirat, Farah, Bamyan… etc.) in Pdf View.Because there are Multipe layers(ManageLayer,GraduatedOverlay,PaiOverlay) for Print





Client Side  :

--------------------





   function btnToPdf_Click(element) {

        var selectItemText = $("#txtTitle").val();

        var size = $("#ddlprintsize").val();

        var Orientation = $("#ddlOrientation").val();

        $(".Load_Div").show();



        var a = Map1.getExtent();

        Map1.ajaxCallAction(’@ViewContext.RouteData.Values[“Controller”].ToString()’, ‘PrintToPDF’, { FromType: $(’#hdnFromType’).val(), ‘selectItemText’: selectItemText, ‘size’: size, ‘Orientation’: Orientation, ‘left’: a.left, ‘top’: a.top, ‘right’: a.right, ‘bottom’: a.bottom, ‘hdnbaselayer’: Map1.baseLayer.id, ‘hdnAssetPrint’: $("#hdnAssetPrint").val(), ‘IsResultPrint’: $("#chkprintresult").attr(‘checked’), ‘hdnWorkunitPrint’: $("#hdnWorkunitPrint").val() }, mapCallback);

        $("#lnkclose").click();

    }









    function mapCallback(result) {

        if (result.get_responseData() == “error”)

            RediredtToLogin(’@Html.Resource(“SessionExpireMessage”)’);

               //window.location = “/GISMapMain/GISMapMainIndex”;

           else if (result.get_responseData() == “errorServer”) {

                alert(’@Html.Resource(“GISMapServicedown”)’);

               // window.location = “/GISMapMain/GISMapMainIndex”;

           }

               //RediredtToLogin(’@Html.Resource(“SessionExpireMessage”)’);



        else {

            var url = “” + window.location.host + result.get_responseData();

            window.open(url);

        }

    $(".Load_Div").hide();

    }



--------------------------------------------------------------------------------------------------------------------------------

Server Side :

------------



  [MapActionFilter]

        public string PrintToPDF(Map map, GeoCollection args)

        {

            try

            {

                if (Comman.CheckSessionFoGIS())

                    return “error”;

                PdfDocument document = new PdfDocument();

                //PdfPage page1 = document.AddPage();

                PdfPage page = document.AddPage();

                string selectedItemText = args[“selectItemText”].ToString();

                if (args[“Orientation”].ToString() == “Landscape”)

                    page.Orientation = PdfSharp.PageOrientation.Landscape;

                else

                    page.Orientation = PageOrientation.Portrait;



                if (args[2].ToString() == “A0”)

                    page.Size = PageSize.A0;

                else if (args[2].ToString() == “A1”)

                    page.Size = PageSize.A1;

                else if (args[2].ToString() == “A2”)

                    page.Size = PageSize.A2;

                else if (args[2].ToString() == “A3”)

                    page.Size = PageSize.A3;

                else if (args[2].ToString() == “A4”)

                    page.Size = PageSize.A4;



                PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();

                List<LayerOverlay> lstlayeroverlay = new List<LayerOverlay>();

                if (args[“IsResultPrint”].ToString() != “checked”)

                {

                    if (args[“hdnbaselayer”].ToString() == “OpenStreetMap”)

                        lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays[“OpenStreetMap”]);

                    else if (args[“hdnbaselayer”].ToString() == “BingMap”)

                        lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays[“BingMap”]);

                    else if (args[“hdnbaselayer”].ToString() == “GoogleMap”)

                        lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays[“GoogleMap”]);

                    else

                        lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays[“WordMap”]);

                }

                lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays[“ManageLayer”]);

                lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays[“GraduatedOverlay”]);

                lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays[“PaiOverlay”]);

                

                //lstlayeroverlay.Add((LayerOverlay)map.CustomOverlays[“LegendOverlay”]);





                XGraphics XGraphics = XGraphics.FromPdfPage(page);

                int headerHeight = 70;

                try

                {



                    XGraphics.DrawImage(XImage.FromFile(Server.MapPath("~/Skin/Img/LeftLogo.png")), new XRect(50, 0, 50, headerHeight));

                    if (!string.IsNullOrEmpty(selectedItemText))

                    {

                        XGraphics.DrawString(selectedItemText, new XFont(“Arial”, 20), XBrushes.Black, new XRect(0, 0, page.Width, headerHeight), XStringFormats.Center);

                    }

                    XGraphics.DrawImage(XImage.FromFile(Server.MapPath("~/Skin/Img/Right Logo.png")), new XRect(page.Width - 100, 0, 50, headerHeight));





                }

                finally

                {

                    XGraphics.Dispose();

                }

                pdfGeoCanvas.DrawingArea = new Rectangle(0, headerHeight, (int)page.Width, (int)page.Height - (headerHeight + headerHeight));

                Collection<SimpleCandidate> labelsInLayers = new Collection<SimpleCandidate>();

                RectangleShape rect = new RectangleShape(double.Parse(args[“left”].ToString()), double.Parse(args[“top”].ToString()), double.Parse(args[“right”].ToString()), double.Parse(args[“bottom”].ToString()));

                string FromType = Convert.ToString(args[“FromType”]);



                foreach (LayerOverlay layeroverlay in lstlayeroverlay)

                {

                    foreach (Layer layer in layeroverlay.Layers)

                    {

                        layer.Open();

                        pdfGeoCanvas.BeginDrawing(page, rect, map.MapUnit);

                        if (layeroverlay.Name == “DynamicOverlay” && ((FromType.Contains(“Asset”) && !string.IsNullOrEmpty(args[“hdnAssetPrint”].ToString())) || (FromType.Contains(“WorkUnit”) && !string.IsNullOrEmpty(args[“hdnWorkunitPrint”].ToString()))))

                        {

                            MsSql2008FeatureSource featureSource = new MsSql2008FeatureSource(ConfigurationManager.AppSettings[“ConnectionString”].ToString(), “GeometryAssetWorkUnit”, “ID”, 1);

                            featureSource.Open();

                            LayerOverlay dynamicOverlay1 = (LayerOverlay)map.CustomOverlays[“DynamicOverlay”];

                            InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay1.Layers[“shapeLayer”];

                            shapeLayer.Open();

                            shapeLayer.Draw(pdfGeoCanvas, labelsInLayers);

                            shapeLayer.Close();

                        }

                        else if (layeroverlay.Name != “DynamicOverlay”)

                        {

                            layer.Draw(pdfGeoCanvas, labelsInLayers);

                        }

                        layer.Transparency = 255;

                        layer.Close();

                        pdfGeoCanvas.EndDrawing();

                    }

                }





                XGraphics = XGraphics.FromPdfPage(page);

                string Physicalpath = HttpContext.Request.PhysicalApplicationPath.Replace(’\’, ‘/’);

                double FooterLegengRowWith1 = 33.68; //((double)page.Width) / 25;

                double FooterLegengRowWith = FooterLegengRowWith1;

                double TempCount = 0, TempHeightCount = 0;



                //string LegendName = “Legend For " + ProjectSession.LegendType + " :”;

                //XGraphics.DrawString(LegendName, new XFont(“Arial”, 8, XFontStyle.Bold), XBrushes.Black, new XRect((FooterLegengRowWith * TempCount) + 10, (page.Height - headerHeight) + (15 * TempHeightCount) + 10, 20, 15), XStringFormats.TopLeft);



                XGraphics.DrawString(“Legend :”, new XFont(“Arial”, 8, XFontStyle.Bold), XBrushes.Black, new XRect((FooterLegengRowWith * TempCount) + 10, (page.Height - headerHeight) + (15 * TempHeightCount) + 10, 20, 15), XStringFormats.TopLeft);

                FooterLegengRowWith = FooterLegengRowWith + FooterLegengRowWith1;



                TempCount = TempCount + 1;





                foreach (var data in ProjectSession.Legend)

                {

                    if (TempCount % 20 == 0)

                    {

                        FooterLegengRowWith = FooterLegengRowWith1;

                        TempHeightCount++;

                    }



                    XColor x = XColor.FromArgb(GetColorFromGeoColor(GeoColor.FromHtml(data.Key)));

                    XBrush brush = new XSolidBrush(x);



                    if (data.Value != null)

                    {

                        XGraphics.DrawRectangle(brush, new XRect((FooterLegengRowWith * TempCount), (page.Height - headerHeight) + (15 * TempHeightCount) + 10, 15, 15));

                        XGraphics.DrawString(data.Value, new XFont(“Arial”, 7), XBrushes.Black, new XRect(((FooterLegengRowWith * TempCount) + ((FooterLegengRowWith * 30) / 100)), (page.Height - headerHeight) + (15 * TempHeightCount) + 10, 20, 15), XStringFormats.TopLeft);

                    }

                    else

                    {

                        XGraphics.DrawRectangle(brush, new XRect((FooterLegengRowWith * TempCount), (page.Height - headerHeight) + (15 * TempHeightCount) + 10, 15, 15));

                        XGraphics.DrawString(string.Empty, new XFont(“Arial”, 7), XBrushes.Black, new XRect(((FooterLegengRowWith * TempCount) + ((FooterLegengRowWith * 30) / 100)), (page.Height - headerHeight) + (15 * TempHeightCount) + 10, 20, 15), XStringFormats.TopLeft);

                    }

                    //FooterLegengRowWith = FooterLegengRowWith + FooterLegengRowWith1;

                    TempCount++;

                    // LegendHtmlWorkunit += "     " + data.AssetType + "   ";

                    //countWorkunit++;

                }

                XGraphics.Dispose();





                string filepath = “~/PrintDocument/” + “MapSuitePDFMap_” + DateTime.Now.Ticks + “.pdf”;

                document.Save(Server.MapPath(filepath));

                return VirtualPathUtility.ToAbsolute(filepath);

            }

            catch (Exception ex)

            {

                return “errorServer”;

            }

            //return “”;

        }



please help me.



Thanks,

Dinesh

Hi dinesh, 
  
 Your topic looks lost style and is very hard to read. 
  
 Could you please put all you code in project and zip it then upload in this post? 
  
 Regards, 
  
 Don

Hi ,



  I am using Print PDF map.

 

  My files are  : Normal _map.png(Normal Map View ),MapPDF.png(Print pdf of Normal map view)





 My problem is i am not able to print labels for province (like Hirat, Farah, Bamyan… etc.) in Pdf View.Because there are Multipe layers(ManageLayer,GraduatedOverlay,PaiOverlay) for Print



please help me.



Thanks,

Dinesh

Map_PDF_(2).zip (1.36 MB)

Hi dinesh,  
  
 I have some questions after read your code. 
  
 1. Could you see your labels in print preview? 
 2. How you pt your label, set as text style in shape layer or put it in a standalone layer? 
  
 From your screen caputure you can see the base map label are printed in pdf image. So I think that should because you forget put your label layer to your pending print collection. For make sure that: 
  
 1. Could you please add break point to monitor whether the label layer have been added to your lstlayeroverlay when you loop to print it? 
 2. Could you please remove base map and set transparent style for your shapes but only show label? I am afraid maybe it’s under the shape when you print it. 
  
 Regards, 
  
 Don