コード例 #1
0
        public LegendProperties(Configuration.PrintTemplateContentRow row)
        {
            OriginX = Convert.ToSingle(row.OriginX) * PointsPerInch;
            OriginY = Convert.ToSingle(row.OriginY) * PointsPerInch;
            Width   = Convert.ToSingle(row.Width) * PointsPerInch;
            Height  = Convert.ToSingle(row.Height) * PointsPerInch;

            string fontFamily = row.IsFontFamilyNull() ? "Helvetica" : row.FontFamily;

            FontSize = row.IsFontSizeNull() ? 12 : Convert.ToSingle(row.FontSize);

            if (!row.IsFontBoldNull() && row.FontBold == 1)
            {
                fontFamily += "-Bold";
            }

            BaseFont = BaseFont.CreateFont(fontFamily, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            SwatchHeight  = FontSize;
            SwatchWidth   = FontSize * 1.4f;
            LayerSpacing  = FontSize * 0.5f;
            ClassSpacing  = FontSize * 0.15f;
            ColumnSpacing = FontSize * 1.4f;

            ColumnWidth = !row.IsLegendColumnWidthNull() ? Convert.ToSingle(row.LegendColumnWidth) * PointsPerInch :
                          FontSize * 12 + SwatchWidth;

            NumColumns = Convert.ToInt32(Math.Floor((Width + ColumnSpacing) / (ColumnWidth + ColumnSpacing)));
        }
コード例 #2
0
    private void CreatePdfLegend(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        CreatePdfBox(content, row);

        LegendProperties properties = new LegendProperties(row);

        if (properties.NumColumns == 0)
        {
            return;
        }

        List <CommonLayer> layerList = GetLegendLayers();

        if (layerList.Count == 0)
        {
            return;
        }

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.FindByMapTabID(_appState.MapTab);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);
        List <CommonLayer>      topLayers = dataFrame.TopLevelLayers;

        properties.CurrentX      = 0;
        properties.CurrentY      = properties.Height;
        properties.CurrentColumn = 1;

        bool full = false;

        for (int i = 0; i < topLayers.Count && !full; ++i)
        {
            full = CreateLayerInLegend(content, mapTab, layerList, properties, topLayers[i], 0);
        }
    }
コード例 #3
0
    private void CreatePdfOverviewMap(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        AppState appState = new AppState();

        appState.Application = _appState.Application;
        Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.First(o => o.ApplicationID == appState.Application);

        appState.MapTab = application.OverviewMapID;
        appState.Extent = application.GetFullExtentEnvelope();

        int pixelWidth  = Convert.ToInt32(row.Width * PixelsPerInch);
        int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch);

        MapMaker     mapMaker     = new MapMaker(appState, pixelWidth, pixelHeight, 2);
        MapImageData mapImageData = mapMaker.GetImage();

        System.Drawing.Bitmap bitmap      = new System.Drawing.Bitmap(new MemoryStream(mapImageData.Image));
        Transformation        trans       = new AffineTransformation(pixelWidth * 2, pixelHeight * 2, appState.Extent);
        MapGraphics           mapGraphics = MapGraphics.FromImage(bitmap, trans);

        double   minSize = (trans.Transform(new Coordinate(1, 0)).X - trans.Transform(new Coordinate(0, 0)).X) * 12;
        Envelope extent  = new Envelope(new Coordinate(_appState.Extent.MinX, _appState.Extent.MinY), new Coordinate(_appState.Extent.MaxX, _appState.Extent.MaxY));

        if (extent.Width < minSize)
        {
            extent = new Envelope(new Coordinate(extent.Centre.X - minSize * 0.5, extent.MinY), new Coordinate(extent.Centre.X + minSize * 0.5, extent.MaxY));
        }

        if (extent.Height < minSize)
        {
            extent = new Envelope(new Coordinate(extent.MinX, extent.Centre.Y - minSize * 0.5), new Coordinate(extent.MaxX, extent.Centre.Y + minSize * 0.5));
        }

        System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(64, System.Drawing.Color.Red));
        System.Drawing.Pen   pen   = new System.Drawing.Pen(System.Drawing.Color.Red, 4);

        mapGraphics.FillEnvelope(brush, extent);
        mapGraphics.DrawEnvelope(pen, extent);

        MemoryStream stream = new MemoryStream();

        bitmap.Save(stream, mapImageData.Type == CommonImageType.Png ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] mapImage = stream.ToArray();

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(mapImage);
        image.SetAbsolutePosition(originX, originY);
        image.ScaleAbsolute(width, height);

        content.AddImage(image);

        CreatePdfBox(content, row, false);
    }
コード例 #4
0
    private void CreatePdfBox(PdfContentByte content, Configuration.PrintTemplateContentRow row, bool allowFill)
    {
        if (row.IsFillColorNull() && row.IsOutlineWidthNull() && row.IsOutlineColorNull())
        {
            return;
        }

        bool hasFill   = false;
        bool hasStroke = false;

        content.SetLineWidth((1 / PixelsPerInch) * PointsPerInch);

        if (!row.IsFillColorNull() && allowFill)
        {
            System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml(row.FillColor);
            content.SetRGBColorFill(c.R, c.G, c.B);
            hasFill = true;
        }

        if (!row.IsOutlineWidthNull())
        {
            content.SetLineWidth((Convert.ToSingle(row.OutlineWidth) / PixelsPerInch) * PointsPerInch);
            hasStroke = true;
        }

        if (!row.IsOutlineColorNull())
        {
            System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml(row.OutlineColor);
            content.SetRGBColorStroke(c.R, c.G, c.B);
            hasStroke = true;
        }

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        if (hasFill)
        {
            content.Rectangle(originX, originY, width, height);
            content.Fill();
        }

        if (hasStroke)
        {
            content.Rectangle(originX, originY, width, height);
            content.Stroke();
        }
    }
コード例 #5
0
    private void CreatePdfTabData(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        CreatePdfBox(content, row);

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        string fontFamily = row.IsFontFamilyNull() ? "Helvetica" : row.FontFamily;
        float  fontSize   = row.IsFontSizeNull() ? 12 : Convert.ToSingle(row.FontSize);

        BaseFont normalFont = BaseFont.CreateFont(fontFamily, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        BaseFont boldFont   = BaseFont.CreateFont(fontFamily + "-Bold", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    }
コード例 #6
0
    private void CreatePdfImage(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("Images/Print") + "\\" + row.FileName);
        image.SetAbsolutePosition(originX, originY);
        image.ScaleAbsolute(width, height);

        content.AddImage(image);

        CreatePdfBox(content, row, false);
    }
コード例 #7
0
ファイル: PrintableMap.aspx.cs プロジェクト: andrewgbuck/GPV
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (AppState.IsIn(ViewState))
        {
            int top = 62;

            foreach (string key in _inputFields.Keys)
            {
                foreach (int i in _inputFields[key])
                {
                    HtmlGenericControl div = FindControl(String.Format("pnlInput{0}", i)) as HtmlGenericControl;
                    div.Visible = key == ddlPrintTemplate.SelectedValue;

                    if (div.Visible)
                    {
                        div.Style["top"] = String.Format("{0}px", top);
                        top += 20;
                    }
                }
            }

            pnlBottom.Style["top"]  = String.Format("{0}px", top + 5);
            pnlMain.Style["height"] = String.Format("{0}px", top + 93);

            AppState appState    = AppState.RestoreFrom(ViewState, false);
            double   extentWidth = appState.Extent.Width;
            double   width       = (double)ViewState["width"];

            if (AppSettings.MapUnits == "meters")
            {
                extentWidth *= Constants.FeetPerMeter;
            }

            labPreserveScale.InnerText = String.Format("[1\" = {0:#,##0} ft]", extentWidth * 96 / width);
            labPreserveWidth.InnerText = String.Format("[{0:#,##0} ft", extentWidth);

            Configuration.PrintTemplateContentRow mapElement = AppContext.GetConfiguration().PrintTemplateContent.Where(o => o.TemplateID == ddlPrintTemplate.SelectedValue).OrderBy(o => o.SequenceNo).FirstOrDefault(o => String.Compare(o.ContentType, "map", true) == 0);

            if (mapElement != null)
            {
                labPreserveWidth.InnerText += String.Format(" or 1\" = {0:#,##0} ft", extentWidth / mapElement.Width);
            }

            labPreserveWidth.InnerText += "]";

            cmdCreate.Enabled = ddlPrintTemplate.SelectedIndex > -1;
        }
    }
コード例 #8
0
    private void CreatePdfTiles(PdfContentByte content, Configuration.PrintTemplateContentRow row, bool overlay)
    {
        int pixelWidth  = Convert.ToInt32(row.Width * PixelsPerInch);
        int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch);

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        StringCollection visibleTiles = _appState.VisibleTiles[_appState.MapTab];
        int level = Convert.ToInt32(Math.Log(Constants.BasePixelSize / _pixelSize, 2));

        if (visibleTiles.Count > 0)
        {
            Configuration.MapTabRow mapTab = AppContext.GetConfiguration().MapTab.FindByMapTabID(_appState.MapTab);

            foreach (Configuration.MapTabTileGroupRow mapTabTileGroup in mapTab.GetMapTabTileGroupRows().Where(o => visibleTiles.Contains(o.TileGroupID)))
            {
                double opacity = mapTabTileGroup.IsOpacityNull() ? 1 : mapTabTileGroup.Opacity;

                foreach (Configuration.TileLayerRow tileLayer in mapTabTileGroup.TileGroupRow.GetTileLayerRows())
                {
                    bool isOverlay = !tileLayer.IsOverlayNull() && tileLayer.Overlay == 1;

                    if (isOverlay == overlay)
                    {
                        byte[] tileImage = TileAggregator.GetImageBytes(tileLayer.URL, _appState.Extent, level, opacity);

                        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(tileImage);
                        image.SetAbsolutePosition(originX, originY);
                        image.ScaleAbsolute(width, height);

                        content.AddImage(image);
                    }
                }
            }
        }
    }
コード例 #9
0
    private void CreatePdfMap(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        int pixelWidth  = Convert.ToInt32(row.Width * PixelsPerInch);
        int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch);

        MapMaker mapMaker = new MapMaker(_appState, pixelWidth, pixelHeight, 2);

        byte[] mapImage = mapMaker.GetImage().Image;

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(mapImage);
        image.SetAbsolutePosition(originX, originY);
        image.ScaleAbsolute(width, height);

        content.AddImage(image);

        CreatePdfBox(content, row, false);
    }
コード例 #10
0
    public void Write(HttpResponse response, bool inline)
    {
        response.Clear();
        response.ContentType = "application/pdf";
        response.AddHeader("Content-Disposition", (inline ? "inline" : "attachment") + "; filename=Map.pdf");

        // create the PDF document

        Configuration config = AppContext.GetConfiguration();

        Configuration.PrintTemplateRow printTemplate = config.PrintTemplate.First(o => o.TemplateID == _templateId);

        float pageWidth  = Convert.ToSingle(printTemplate.PageWidth * PointsPerInch);
        float pageHeight = Convert.ToSingle(printTemplate.PageHeight * PointsPerInch);

        Rectangle pageSize = new Rectangle(pageWidth, pageHeight);

        pageSize.BackgroundColor = new Color(System.Drawing.Color.White);
        Document document = new Document(pageSize);

        PdfWriter writer = PdfWriter.GetInstance(document, response.OutputStream);

        document.Open();
        PdfContentByte content = writer.DirectContent;

        // get the extent of the main map and fit it to the proportions of
        // the map box on the page

        double mapScale = 0;

        Configuration.PrintTemplateContentRow mapElement = printTemplate.GetPrintTemplateContentRows().FirstOrDefault(o => o.ContentType == "map");

        if (mapElement != null)
        {
            if (_preserveMode == PreserveMode.Extent)
            {
                _appState.Extent.Reaspect(mapElement.Width, mapElement.Height);
            }
            else
            {
                IPoint c = new Point(_appState.Extent.Centre);

                double dx;
                double dy;

                if (_preserveMode == PreserveMode.Scale)
                {
                    double ratio = _appState.Extent.Width * 96 / _originalWidth;
                    dx = mapElement.Width * ratio * 0.5;
                    dy = mapElement.Height * ratio * 0.5;
                }
                else
                {
                    dx = _appState.Extent.Width * 0.5;
                    dy = dx * mapElement.Height / mapElement.Width;
                }

                _appState.Extent = new Envelope(new Coordinate(c.Coordinate.X - dx, c.Coordinate.Y - dy), new Coordinate(c.Coordinate.X + dx, c.Coordinate.Y + dy));
            }

            double conversion = AppContext.AppSettings.MapUnits == "feet" ? 1 : Constants.FeetPerMeter;
            mapScale = _appState.Extent.Width * conversion / mapElement.Width;

            _pixelSize = _appState.Extent.Width / (mapElement.Width * PixelsPerInch);
        }

        int inputIndex = 0;

        // get the page template elements and draw each one to the page

        foreach (Configuration.PrintTemplateContentRow element in printTemplate.GetPrintTemplateContentRows())
        {
            switch (element.ContentType)
            {
            case "box":
                CreatePdfBox(content, element);
                break;

            case "date":
                CreatePdfText(content, element, DateTime.Now.ToString("MMMM d, yyyy"));
                break;

            case "image":
                CreatePdfImage(content, element);
                break;

            case "legend":
                CreatePdfLegend(content, element);
                break;

            case "map":
                CreatePdfMap(content, element);
                break;

            case "overviewmap":
                CreatePdfOverviewMap(content, element);
                break;

            case "scale":
                if (mapScale > 0)
                {
                    CreatePdfText(content, element, "1\" = " + mapScale.ToString("0") + " ft");
                }
                break;

            case "scalefeet":
                if (mapScale > 0)
                {
                    CreatePdfText(content, element, mapScale.ToString("0") + " ft");
                }
                break;

            case "tabdata":
                CreatePdfTabData(content, element);
                break;

            case "text":
                if (!element.IsTextNull())
                {
                    CreatePdfText(content, element, element.Text);
                }
                else if (!element.IsFileNameNull())
                {
                    string fileName = HttpContext.Current.Server.MapPath("Text/Print") + "\\" + element.FileName;

                    if (File.Exists(fileName))
                    {
                        string text = File.ReadAllText(fileName);
                        CreatePdfText(content, element, text);
                    }
                }
                break;

            case "input":
                if (inputIndex < _input.Count)
                {
                    CreatePdfText(content, element, _input[inputIndex]);
                    ++inputIndex;
                }
                break;
            }
        }

        document.Close();
        response.End();
    }
コード例 #11
0
 private void CreatePdfBox(PdfContentByte content, Configuration.PrintTemplateContentRow row)
 {
     CreatePdfBox(content, row, true);
 }
コード例 #12
0
    private void CreatePdfText(PdfContentByte content, Configuration.PrintTemplateContentRow row, string text)
    {
        CreatePdfBox(content, row);

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        string fontFamily = "Helvetica";
        int    textAlign  = PdfContentByte.ALIGN_CENTER;
        float  fontSize   = 12;
        int    textStyle  = iTextSharp.text.Font.NORMAL;
        bool   textWrap   = false;

        int columnAlign = Element.ALIGN_CENTER;

        if (!row.IsTextWrapNull())
        {
            textWrap = row.TextWrap == 1;
        }

        if (!row.IsFontFamilyNull())
        {
            fontFamily = row.FontFamily;
        }

        if (!row.IsFontBoldNull())
        {
            if (row.FontBold == 1)
            {
                if (textWrap)
                {
                    textStyle = Font.BOLD;
                }
                else
                {
                    fontFamily += "-Bold";
                }
            }
        }

        if (!row.IsFontSizeNull())
        {
            fontSize = Convert.ToSingle(row.FontSize);
        }

        BaseFont baseFont = BaseFont.CreateFont(fontFamily, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        if (textWrap)
        {
            if (!row.IsTextAlignNull())
            {
                switch (row.TextAlign)
                {
                case "left":
                    columnAlign = Element.ALIGN_LEFT;
                    break;

                case "right":
                    columnAlign = Element.ALIGN_RIGHT;
                    break;
                }
            }

            Font font = new Font(baseFont, fontSize, textStyle);
            content.SetRGBColorFill(0, 0, 0);

            float leading = fontSize * 1.2f;

            ColumnText column = new ColumnText(content);
            column.SetSimpleColumn(originX, originY, originX + width, originY + height, leading, columnAlign);
            column.AddText(new Phrase(leading, text, font));
            column.Go();
        }
        else
        {
            originX += width / 2;

            if (!row.IsTextAlignNull())
            {
                switch (row.TextAlign)
                {
                case "left":
                    textAlign = PdfContentByte.ALIGN_LEFT;
                    originX  -= width / 2;
                    break;

                case "right":
                    textAlign = PdfContentByte.ALIGN_RIGHT;
                    originX  += width / 2;
                    break;
                }
            }

            content.BeginText();
            content.SetFontAndSize(baseFont, fontSize);
            content.SetRGBColorFill(0, 0, 0);
            content.ShowTextAligned(textAlign, text, originX, originY, 0);
            content.EndText();
        }
    }