// Here we setup the PDF page and then create our PDFGeoCanvas.
        // We loop through all the layers to draw and then save & pop the
        // PDF
        private void btnToPdf_Click(object sender, EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            PdfPage page = document.AddPage();
            if (pageOrientationLandscape.IsChecked == true)
            {
                page.Orientation = PageOrientation.Landscape;
            }

            PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();

            // This allows you to control the area in which you want the
            // map to draw in.  Leaving this commented out uses the whole page
            //pdfGeoCanvas.DrawingArea = new Rectangle(200, 50, 400, 400);
            Collection<SimpleCandidate> labelsInLayers = new Collection<SimpleCandidate>();
            pdfGeoCanvas.BeginDrawing(page, wpfMap1.CurrentExtent, GeographyUnit.DecimalDegree);
            foreach (Layer layer in ((LayerOverlay)wpfMap1.Overlays[0]).Layers)
            {
                layer.Open();
                layer.Draw(pdfGeoCanvas, labelsInLayers);
                layer.Close();
            }
            pdfGeoCanvas.EndDrawing();
            string filename = GetTemporaryFolder() + "\\MapSuite PDF Map.pdf";
            try
            {
                document.Save(filename);
                OpenPdfFile(filename);
            }
            catch (Exception ex)
            {
                string message = "You have no permission to write file to disk." + ex.Message;
                MessageBox.Show(message, "No permission", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, (MessageBoxOptions)0);
            }
        }
예제 #2
0
        public string ToPdf(Map map, GeoCollection <object> 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();

            // This allows you to control the area in which you want the
            // map to draw in.  Leaving this commented out uses the whole page
            //pdfGeoCanvas.DrawingArea = new Rectangle(200, 50, 400, 400);
            Collection <SimpleCandidate> labelsInLayers = new Collection <SimpleCandidate>();

            foreach (Layer layer in map.StaticOverlay.Layers)
            {
                RectangleShape printExtent = ExtentHelper.GetDrawingExtent(map.CurrentExtent, (float)map.WidthInPixels, (float)map.HeightInPixels);
                pdfGeoCanvas.BeginDrawing(page, printExtent, 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));
        }
        // Here we setup the PDF page and then create our PDFGeoCanvas.
        // We loop through all the layers to draw and then save & pop the
        // PDF
        private void btnToPdf_Click(object sender, EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            if (pageOrientationLandscape.Checked == true)
            {
                page.Orientation = PageOrientation.Landscape;
            }

            PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();

            // This allows you to control the area in which you want the
            // map to draw in.  Leaving this commented out uses the whole page
            //pdfGeoCanvas.DrawingArea = new Rectangle(200, 50, 400, 400);
            Collection <SimpleCandidate> labelsInLayers = new Collection <SimpleCandidate>();

            foreach (Layer layer in ((LayerOverlay)winformsMap1.Overlays[0]).Layers)
            {
                pdfGeoCanvas.BeginDrawing(page, winformsMap1.CurrentExtent, GeographyUnit.DecimalDegree);
                layer.Open();
                layer.Draw(pdfGeoCanvas, labelsInLayers);
                layer.Close();
                pdfGeoCanvas.EndDrawing();
            }

            string filename = GetTemporaryFolder() + "\\MapSuite PDF Map.pdf";

            try
            {
                document.Save(filename);
                OpenPdfFile(filename);
            }
            catch (Exception ex)
            {
                string message = "You have no permission to write file to disk." + ex.Message;
                MessageBox.Show(message, "Not permitted", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
            }
        }