public static void Draw(Context grw, RectangleElement rect) { if (rect.Foregraund != null) { grw.SetSourceRGBA ( rect.Foregraund.Red, rect.Foregraund.Green, rect.Foregraund.Blue, rect.Alpha); } grw.Rectangle ( new Rectangle ( rect.LeftBottom.GeometryX, rect.LeftBottom.GeometryY, rect.GeometryWidth, rect.GeometryHeight)); grw.StrokePreserve(); grw.Fill(); }
private void btnCreatePdf_Click(object sender, EventArgs e) { // create a PDF document Document document = new Document(); // set the license key document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE="; // add a page to the PDF document PdfPage firstPage = document.AddPage(); // draw rectangle RectangleElement rectangle1 = new RectangleElement(10, 10, 150, 100); rectangle1.ForeColor = System.Drawing.Color.Blue; rectangle1.LineStyle.LineWidth = 5; // a 5 points line width rectangle1.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin; firstPage.AddElement(rectangle1); // draw colored rectangle RectangleElement rectangle2 = new RectangleElement(200, 10, 150, 100); rectangle2.ForeColor = System.Drawing.Color.Blue; rectangle2.BackColor = System.Drawing.Color.Green; firstPage.AddElement(rectangle2); // draw gradient colored rectangle RectangleElement rectangle3 = new RectangleElement(400, 25, 100, 50); rectangle3.ForeColor = System.Drawing.Color.Blue; rectangle3.Gradient = new GradientColor(GradientDirection.Vertical, System.Drawing.Color.Green, System.Drawing.Color.Blue); firstPage.AddElement(rectangle3); // draw ellipse EllipseElement ellipse1 = new EllipseElement(75, 200, 70, 50); ellipse1.ForeColor = System.Drawing.Color.Blue; ellipse1.LineStyle.LineDashStyle = LineDashStyle.Dash; firstPage.AddElement(ellipse1); // draw ellipse EllipseElement ellipse2 = new EllipseElement(275, 200, 70, 50); ellipse2.ForeColor = System.Drawing.Color.Blue; ellipse2.BackColor = System.Drawing.Color.Green; firstPage.AddElement(ellipse2); // draw ellipse EllipseElement ellipse3 = new EllipseElement(450, 200, 50, 25); ellipse3.ForeColor = System.Drawing.Color.Blue; ellipse3.Gradient = new GradientColor(GradientDirection.Vertical, System.Drawing.Color.Green, System.Drawing.Color.Blue); firstPage.AddElement(ellipse3); BezierCurveElement bezierCurve1 = new BezierCurveElement(10, 350, 100, 300, 200, 400, 300, 350); bezierCurve1.ForeColor = System.Drawing.Color.Blue; bezierCurve1.LineStyle.LineWidth = 3; bezierCurve1.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin; firstPage.AddElement(bezierCurve1); BezierCurveElement bezierCurve2 = new BezierCurveElement(10, 350, 100, 400, 200, 300, 300, 350); bezierCurve2.ForeColor = System.Drawing.Color.Green; bezierCurve2.LineStyle.LineWidth = 3; bezierCurve2.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin; firstPage.AddElement(bezierCurve2); string outFilePath = System.IO.Path.Combine(Application.StartupPath, "ShapesDemo.pdf"); // save the PDF document to disk document.Save(outFilePath); // close the PDF document to release the resources document.Close(); DialogResult dr = MessageBox.Show("Open the saved file in an external viewer?", "Open Rendered File", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { try { System.Diagnostics.Process.Start(outFilePath); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } }
protected void btnCreatePDF_Click(object sender, EventArgs e) { string pdfToModify = textBoxPdfFilePath.Text.Trim(); // create a PDF document Document document = new Document(pdfToModify); // set the license key document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE="; // get the first page the PDF document PdfPage firstPage = document.Pages[0]; string logoTransImagePath = System.IO.Path.Combine(Server.MapPath("~"), @"images\evologo-100-trans.png"); string logoOpaqueImagePath = System.IO.Path.Combine(Server.MapPath("~"), @"images\evologo-100.jpg"); // add an opaque image stamp in the top left corner of the first page // and make it semitransparent when rendered in PDF ImageElement imageStamp = new ImageElement(1, 1, logoOpaqueImagePath); imageStamp.Opacity = 50; AddElementResult addResult = firstPage.AddElement(imageStamp); // add a border for the image stamp RectangleElement imageBorderRectangleElement = new RectangleElement(1, 1, addResult.EndPageBounds.Width, addResult.EndPageBounds.Height); firstPage.AddElement(imageBorderRectangleElement); // add a template stamp to the document repeated on each document page // the template contains an image and a text System.Drawing.Image logoImg = System.Drawing.Image.FromFile(logoTransImagePath); // calculate the template stamp location and size System.Drawing.SizeF imageSizePx = logoImg.PhysicalDimension; float imageWidthPoints = UnitsConverter.PixelsToPoints(imageSizePx.Width); float imageHeightPoints = UnitsConverter.PixelsToPoints(imageSizePx.Height); float templateStampXLocation = (firstPage.ClientRectangle.Width - imageWidthPoints) / 2; float templateStampYLocation = firstPage.ClientRectangle.Height / 4; // the stamp size is equal to image size in points Template templateStamp = document.AddTemplate(new System.Drawing.RectangleF(templateStampXLocation, templateStampYLocation, imageWidthPoints, imageHeightPoints + 20)); // set a semitransparent background color for template RectangleElement background = new RectangleElement(0, 0, templateStamp.ClientRectangle.Width, templateStamp.ClientRectangle.Height); background.BackColor = Color.White; background.Opacity = 25; templateStamp.AddElement(background); // add a true type font to the document System.Drawing.Font ttfFontBoldItalic = new System.Drawing.Font("Times New Roman", 10, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point); PdfFont templateStampTextFont = document.AddFont(ttfFontBoldItalic, true); // Add a text element to the template. You can add any other types of elements to a template like a HtmlToPdfElement. TextElement templateStampTextElement = new TextElement(3, 0, "This is the Stamp Text", templateStampTextFont); templateStampTextElement.ForeColor = System.Drawing.Color.DarkBlue; templateStamp.AddElement(templateStampTextElement); // Add an image with transparency to the template. You can add any other types of elements to a template like a HtmlToPdfElement. ImageElement templateStampImageElement = new ImageElement(0, 20, logoImg); // instruct the library to use transparency information templateStampImageElement.RenderTransparentImage = true; templateStamp.AddElement(templateStampImageElement); // add a border to template RectangleElement templateStampRectangleElement = new RectangleElement(0, 0, templateStamp.ClientRectangle.Width, templateStamp.ClientRectangle.Height); templateStamp.AddElement(templateStampRectangleElement); // dispose the image logoImg.Dispose(); // save the document on http response stream try { // get the PDF document bytes byte[] pdfBytes = document.Save(); // send the generated PDF document to client browser // get the object representing the HTTP response to browser HttpResponse httpResponse = HttpContext.Current.Response; // add the Content-Type and Content-Disposition HTTP headers httpResponse.AddHeader("Content-Type", "application/pdf"); httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename=PdfStamps.pdf; size={0}", pdfBytes.Length.ToString())); // write the PDF document bytes as attachment to HTTP response httpResponse.BinaryWrite(pdfBytes); // Note: it is important to end the response, otherwise the ASP.NET // web page will render its content to PDF document stream httpResponse.End(); } finally { document.Close(); } }
void RecreateRectangles() { delayRecreateRectanglesCalled = false; if (wpfHexView.IsClosed) return; RemoveAllRectangles(); if (!enabled) return; if (wpfHexView.ViewportHeight == 0) return; var line = wpfHexView.HexViewLines.FirstVisibleLine; var top = wpfHexView.ViewportTop; var bottom = wpfHexView.ViewportBottom; foreach (var info in GetRectanglePositions(line)) { var props = editorFormatMap.GetProperties(GetClassificationTypeName(info.Key)); var bgBrush = GetBackgroundBrush(props); if (bgBrush == null || TWPF.BrushComparer.Equals(bgBrush, Brushes.Transparent)) continue; var lineElem = new RectangleElement(info.Key, info.Value, bgBrush, null); bool added = adornmentLayer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, lineElem, null); if (added) rectangleElements.Add(lineElem); } latestBufferLines = wpfHexView.BufferLines; }
protected void btnConvert_Click(object sender, EventArgs e) { PdfConverter pdfConverter = new PdfConverter(); // set the license key - required pdfConverter.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE="; // inform the converter about the HTML elements for which we want the location in PDF // in this sample we want the location of IMG, H1 and H2 elements and the elements with ID // equal to 'id1' or 'id2' pdfConverter.HtmlElementsMappingOptions.HtmlElementSelectors = new string[] { "IMG", "H1", "H2", "#id1", "#id2" }; // call the converter and get a Document object from URL Document pdfDocument = pdfConverter.GetPdfDocumentObjectFromUrl(textBoxWebPageURL.Text.Trim()); // iterate over the HTML elements locations and hightlight each element with a green rectangle foreach (HtmlElementMapping elementMapping in pdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult) { // because a HTML element can span over many PDF pages the mapping // of the HTML element in PDF document consists in a list of rectangles, // one rectangle for each PDF page where this element was rendered foreach (HtmlElementPdfRectangle elementLocationInPdf in elementMapping.PdfRectangles) { // get the PDF page PdfPage pdfPage = pdfDocument.Pages[elementLocationInPdf.PageIndex]; RectangleF pdfRectangleInPage = elementLocationInPdf.Rectangle; // create a RectangleElement to highlight the HTML element RectangleElement highlightRectangle = new RectangleElement(pdfRectangleInPage.X, pdfRectangleInPage.Y, pdfRectangleInPage.Width, pdfRectangleInPage.Height); highlightRectangle.ForeColor = Color.Green; pdfPage.AddElement(highlightRectangle); } } byte[] pdfBytes = null; try { pdfBytes = pdfDocument.Save(); } finally { // close the Document to realease all the resources pdfDocument.Close(); } // send the generated PDF document to client browser // get the object representing the HTTP response to browser HttpResponse httpResponse = HttpContext.Current.Response; // add the Content-Type and Content-Disposition HTTP headers httpResponse.AddHeader("Content-Type", "application/pdf"); httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename=HtmlElementsLocation.pdf; size={0}", pdfBytes.Length.ToString())); // write the PDF document bytes as attachment to HTTP response httpResponse.BinaryWrite(pdfBytes); // Note: it is important to end the response, otherwise the ASP.NET // web page will render its content to PDF document stream httpResponse.End(); }
private void btnCreatePdf_Click(object sender, EventArgs e) { string pdfToModify = textBoxPdfFilePath.Text.Trim(); // create a PDF document Document document = new Document(pdfToModify); // set the license key document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE="; // get the first page the PDF document PdfPage firstPage = document.Pages[0]; string logoTransImagePath = System.IO.Path.Combine(Application.StartupPath, @"..\..\img\evologo-100-trans.png"); string logoOpaqueImagePath = System.IO.Path.Combine(Application.StartupPath, @"..\..\img\evologo-100.jpg"); // add an opaque image stamp in the top left corner of the first page // and make it semitransparent when rendered in PDF ImageElement imageStamp = new ImageElement(1, 1, logoOpaqueImagePath); imageStamp.Opacity = 50; AddElementResult addResult = firstPage.AddElement(imageStamp); // add a border for the image stamp RectangleElement imageBorderRectangleElement = new RectangleElement(1, 1, addResult.EndPageBounds.Width, addResult.EndPageBounds.Height); firstPage.AddElement(imageBorderRectangleElement); // add a template stamp to the document repeated on each document page // the template contains an image and a text System.Drawing.Image logoImg = System.Drawing.Image.FromFile(logoTransImagePath); // calculate the template stamp location and size System.Drawing.SizeF imageSizePx = logoImg.PhysicalDimension; float imageWidthPoints = UnitsConverter.PixelsToPoints(imageSizePx.Width); float imageHeightPoints = UnitsConverter.PixelsToPoints(imageSizePx.Height); float templateStampXLocation = (firstPage.ClientRectangle.Width - imageWidthPoints) / 2; float templateStampYLocation = firstPage.ClientRectangle.Height / 4; // the stamp size is equal to image size in points Template templateStamp = document.AddTemplate(new System.Drawing.RectangleF(templateStampXLocation, templateStampYLocation, imageWidthPoints, imageHeightPoints + 20)); // set a semitransparent background color for template RectangleElement background = new RectangleElement(0, 0, templateStamp.ClientRectangle.Width, templateStamp.ClientRectangle.Height); background.BackColor = Color.White; background.Opacity = 25; templateStamp.AddElement(background); // add a true type font to the document System.Drawing.Font ttfFontBoldItalic = new System.Drawing.Font("Times New Roman", 10, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point); PdfFont templateStampTextFont = document.AddFont(ttfFontBoldItalic, true); // Add a text element to the template. You can add any other types of elements to a template like a HtmlToPdfElement. TextElement templateStampTextElement = new TextElement(3, 0, "This is the Stamp Text", templateStampTextFont); templateStampTextElement.ForeColor = System.Drawing.Color.DarkBlue; templateStamp.AddElement(templateStampTextElement); // Add an image with transparency to the template. You can add any other types of elements to a template like a HtmlToPdfElement. ImageElement templateStampImageElement = new ImageElement(0, 20, logoImg); // instruct the library to use transparency information templateStampImageElement.RenderTransparentImage = true; templateStamp.AddElement(templateStampImageElement); // add a border to template RectangleElement templateStampRectangleElement = new RectangleElement(0, 0, templateStamp.ClientRectangle.Width, templateStamp.ClientRectangle.Height); templateStamp.AddElement(templateStampRectangleElement); // dispose the image logoImg.Dispose(); string outFilePath = System.IO.Path.Combine(Application.StartupPath, "PdfStamps.pdf"); // save the PDF document to disk try { document.Save(outFilePath); } finally { document.Close(); } DialogResult dr = MessageBox.Show("Open the saved file in an external viewer?", "Open Rendered File", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { try { System.Diagnostics.Process.Start(outFilePath); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } }
public void Refresh() { //If the selection does not support IGxDataset, do nothing. IGxSelection pSelection = null; IGxObject pLocation = null; IGraphicsContainer pGraphicsLayer = null; try { pSelection = m_pSelection; pLocation = pSelection.Location; if (!(pLocation is IGxDataset)) return; //Clear the contents of the graphics layer. pGraphicsLayer = (IGraphicsContainer)frmExtentView.AxMapControl1.Map.BasicGraphicsLayer; pGraphicsLayer.DeleteAllElements(); //Some dataset may not have content at all IGxDataset pGxDataset = null; IGeoDataset pGeoDataset = null; IElement pElement = null; IFillShapeElement pFillShapeElement = null; try { //Get the geodataset out of the GxDataset. pGxDataset = (IGxDataset)pLocation; if (pGxDataset.Type == esriDatasetType.esriDTLayer | pGxDataset.Type == esriDatasetType.esriDTFeatureClass | pGxDataset.Type == esriDatasetType.esriDTFeatureDataset) { pGeoDataset = (IGeoDataset)pGxDataset.Dataset; } else { return; } //Create a rectangular graphic element to represent the geodataset's full extent. pElement = new RectangleElement(); pElement.Geometry = pGeoDataset.Extent; //Set the element's symbology. pFillShapeElement = (IFillShapeElement)pElement; pFillShapeElement.Symbol = m_pFillSymbol; //Add the rectangle element to the graphics layer, and force the map to redraw. pGraphicsLayer.AddElement(pElement, 0); frmExtentView.AxMapControl1.Refresh(); } catch (Exception ex) { frmExtentView.AxMapControl1.Refresh(); throw ex; } finally { pGxDataset = null; pGeoDataset = null; pElement = null; pFillShapeElement = null; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { pSelection = null; pLocation = null; pGraphicsLayer = null; } }
private void btnConvert_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { PdfConverter pdfConverter = new PdfConverter(); // set the license key pdfConverter.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE="; // inform the converter about the HTML elements for which we want the location in PDF // in this sample we want the location of IMG, H1 and H2 elements and the elements having ID 'id1' or 'id2' pdfConverter.HtmlElementsMappingOptions.HtmlElementSelectors = new string[] { "IMG", "H1", "H2", "#id1", "#id2" }; // call the converter and get a Document object from URL Document pdfDocument = pdfConverter.GetPdfDocumentObjectFromUrl(textBoxURL.Text.Trim()); // iterate over the HTML elements locations and hightlight each element with a green rectangle foreach (HtmlElementMapping elementMapping in pdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult) { // because a HTML element can span over many PDF pages the mapping // of the HTML element in PDF document consists in a list of rectangles, // one rectangle for each PDF page where this element was rendered foreach (HtmlElementPdfRectangle elementLocationInPdf in elementMapping.PdfRectangles) { // get the PDF page PdfPage pdfPage = pdfDocument.Pages[elementLocationInPdf.PageIndex]; RectangleF pdfRectangleInPage = elementLocationInPdf.Rectangle; // create a RectangleElement to highlight the HTML element RectangleElement highlightRectangle = new RectangleElement(pdfRectangleInPage.X, pdfRectangleInPage.Y, pdfRectangleInPage.Width, pdfRectangleInPage.Height); highlightRectangle.ForeColor = Color.Green; pdfPage.AddElement(highlightRectangle); } } // save the PDF bytes in a file on disk string outFilePath = System.IO.Path.Combine(Application.StartupPath, "HtmlElementsLocation.pdf"); try { pdfDocument.Save(outFilePath); } finally { // close the Document to realease all the resources pdfDocument.Close(); } // open the generated PDF document in an external viewer DialogResult dr = MessageBox.Show("Open the rendered file in an external viewer?", "Open Rendered File", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { System.Diagnostics.Process.Start(outFilePath); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { this.Cursor = Cursors.Arrow; } }
protected void btnCreatePDF_Click(object sender, EventArgs e) { // create a PDF document Document document = new Document(); // set the license key document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE="; // add a page to the PDF document PdfPage firstPage = document.AddPage(); // draw rectangle RectangleElement rectangle1 = new RectangleElement(10, 10, 150, 100); rectangle1.ForeColor = System.Drawing.Color.Blue; rectangle1.LineStyle.LineWidth = 5; // a 5 points line width rectangle1.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin; firstPage.AddElement(rectangle1); // draw colored rectangle RectangleElement rectangle2 = new RectangleElement(200, 10, 150, 100); rectangle2.ForeColor = System.Drawing.Color.Blue; rectangle2.BackColor = System.Drawing.Color.Green; firstPage.AddElement(rectangle2); // draw gradient colored rectangle RectangleElement rectangle3 = new RectangleElement(400, 25, 100, 50); rectangle3.ForeColor = System.Drawing.Color.Blue; rectangle3.Gradient = new GradientColor(GradientDirection.Vertical, System.Drawing.Color.Green, System.Drawing.Color.Blue); firstPage.AddElement(rectangle3); // draw ellipse EllipseElement ellipse1 = new EllipseElement(75, 200, 70, 50); ellipse1.ForeColor = System.Drawing.Color.Blue; ellipse1.LineStyle.LineDashStyle = LineDashStyle.Dash; firstPage.AddElement(ellipse1); // draw ellipse EllipseElement ellipse2 = new EllipseElement(275, 200, 70, 50); ellipse2.ForeColor = System.Drawing.Color.Blue; ellipse2.BackColor = System.Drawing.Color.Green; firstPage.AddElement(ellipse2); // draw ellipse EllipseElement ellipse3 = new EllipseElement(450, 200, 50, 25); ellipse3.ForeColor = System.Drawing.Color.Blue; ellipse3.Gradient = new GradientColor(GradientDirection.Vertical, System.Drawing.Color.Green, System.Drawing.Color.Blue); firstPage.AddElement(ellipse3); BezierCurveElement bezierCurve1 = new BezierCurveElement(10, 350, 100, 300, 200, 400, 300, 350); bezierCurve1.ForeColor = System.Drawing.Color.Blue; bezierCurve1.LineStyle.LineWidth = 3; bezierCurve1.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin; firstPage.AddElement(bezierCurve1); BezierCurveElement bezierCurve2 = new BezierCurveElement(10, 350, 100, 400, 200, 300, 300, 350); bezierCurve2.ForeColor = System.Drawing.Color.Green; bezierCurve2.LineStyle.LineWidth = 3; bezierCurve2.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin; firstPage.AddElement(bezierCurve2); try { // get the PDF document bytes byte[] pdfBytes = document.Save(); // send the generated PDF document to client browser // get the object representing the HTTP response to browser HttpResponse httpResponse = HttpContext.Current.Response; // add the Content-Type and Content-Disposition HTTP headers httpResponse.AddHeader("Content-Type", "application/pdf"); httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename=Shapes.pdf; size={0}", pdfBytes.Length.ToString())); // write the PDF document bytes as attachment to HTTP response httpResponse.BinaryWrite(pdfBytes); // Note: it is important to end the response, otherwise the ASP.NET // web page will render its content to PDF document stream httpResponse.End(); } finally { // close the PDF document to release the resources document.Close(); } }
public override void Visit(RectangleElement rectangle) { _graphics.DrawRectangle(_pen, rectangle.Rect); }
/// <summary> /// 添加图元 /// </summary> /// <param name="pGeometry"></param> /// <param name="pActiveView"></param> /// <param name="pSymbol"></param> /// <param name="key"></param> /// <returns></returns> public IElement AddElement(IGeometry pGeometry, ISymbol pSymbol, string key) { try { IActiveView pActiveView = MapControl.ActiveView; IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer; IElement pElement = null; ILineElement pLineElement = null; IFillShapeElement pFillShapeElement = null; IMarkerElement pMarkerElement = null; ICircleElement pCircleElement = null; IElementProperties pElmentProperties = null; switch (pGeometry.GeometryType) { case esriGeometryType.esriGeometryEnvelope: { pElement = new RectangleElement(); pElement.Geometry = pGeometry; pFillShapeElement = (IFillShapeElement)pElement; pFillShapeElement.Symbol = (IFillSymbol)pSymbol; break; } case esriGeometryType.esriGeometryPolyline: { pElement = new LineElement(); pElement.Geometry = pGeometry; pLineElement = (ILineElement)pElement; pLineElement.Symbol = (ILineSymbol)pSymbol; break; } case esriGeometryType.esriGeometryLine: { pElement = new LineElement(); pElement.Geometry = pGeometry; pLineElement = (ILineElement)pElement; pLineElement.Symbol = (ILineSymbol)pSymbol; break; } case esriGeometryType.esriGeometryPolygon: { pElement = new PolygonElement(); pElement.Geometry = pGeometry; pFillShapeElement = (IFillShapeElement)pElement; pFillShapeElement.Symbol = (IFillSymbol)pSymbol; break; } case esriGeometryType.esriGeometryMultipoint: case esriGeometryType.esriGeometryPoint: { pElement = new MarkerElement(); pElement.Geometry = pGeometry; pMarkerElement = (IMarkerElement)pElement; pMarkerElement.Symbol = (IMarkerSymbol)pSymbol; break; } case esriGeometryType.esriGeometryCircularArc: { pElement = new CircleElement(); pElement.Geometry = pGeometry; pCircleElement = (ICircleElement)pElement; break; } default: pElement = null; break; } if (pElement != null) { pElmentProperties = pElement as IElementProperties; pElmentProperties.Name = key; pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope); return(pElement); } else { return(null); } } catch (Exception ex) { return(null); } }
protected void convertToPdfButton_Click(object sender, EventArgs e) { // Create a HTML to PDF converter object with default settings HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(); // Set license key received after purchase to use the converter in licensed mode // Leave it not set to use the converter in demo mode htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c="; // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish htmlToPdfConverter.ConversionDelay = 2; // Select the HTML elements for which to retrieve location and other information from HTML document htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementSelectors = new string[] { htmlElementsSelectorTextBox.Text }; Document pdfDocument = null; try { // Convert HTML page to a PDF document object which can be further modified to highlight the selected elements pdfDocument = htmlToPdfConverter.ConvertUrlToPdfDocumentObject(urlTextBox.Text); // Highlight the selected elements in PDF with colored rectangles foreach (HtmlElementMapping htmlElementInfo in htmlToPdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult) { // Get other information about HTML element string htmlElementTagName = htmlElementInfo.HtmlElementTagName; string htmlElementID = htmlElementInfo.HtmlElementId; // Hightlight the HTML element in PDF // A HTML element can span over many PDF pages and therefore the mapping of the HTML element in PDF document consists // in a list of rectangles, one rectangle for each PDF page where this element was rendered foreach (HtmlElementPdfRectangle htmlElementLocationInPdf in htmlElementInfo.PdfRectangles) { // Get the HTML element location in PDF page PdfPage htmlElementPdfPage = htmlElementLocationInPdf.PdfPage; RectangleF htmlElementRectangleInPdfPage = htmlElementLocationInPdf.Rectangle; // Highlight the HTML element element with a colored rectangle in PDF RectangleElement highlightRectangle = new RectangleElement(htmlElementRectangleInPdfPage.X, htmlElementRectangleInPdfPage.Y, htmlElementRectangleInPdfPage.Width, htmlElementRectangleInPdfPage.Height); if (htmlElementTagName.ToLower() == "h1") { highlightRectangle.ForeColor = Color.Blue; } else if (htmlElementTagName.ToLower() == "h2") { highlightRectangle.ForeColor = Color.Green; } else if (htmlElementTagName.ToLower() == "h3") { highlightRectangle.ForeColor = Color.Red; } else if (htmlElementTagName.ToLower() == "h4") { highlightRectangle.ForeColor = Color.Yellow; } else if (htmlElementTagName.ToLower() == "h5") { highlightRectangle.ForeColor = Color.Indigo; } else if (htmlElementTagName.ToLower() == "h6") { highlightRectangle.ForeColor = Color.Orange; } else { highlightRectangle.ForeColor = Color.Navy; } highlightRectangle.LineStyle.LineDashStyle = LineDashStyle.Solid; htmlElementPdfPage.AddElement(highlightRectangle); } } // Save the PDF document in a memory buffer byte[] outPdfBuffer = pdfDocument.Save(); // Send the PDF as response to browser // Set response content type Response.AddHeader("Content-Type", "application/pdf"); // Instruct the browser to open the PDF file as an attachment or inline Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Select_in_API_HTML_Elements_to_Retrieve.pdf; size={0}", outPdfBuffer.Length.ToString())); // Write the PDF document buffer to HTTP response Response.BinaryWrite(outPdfBuffer); // End the HTTP response and stop the current page processing Response.End(); } finally { // Close the PDF document if (pdfDocument != null) { pdfDocument.Close(); } } }
public void CreateTable(IActiveView pAV, IPoint Leftdown, object tabcell) { IPoint y; int i; this.m_tabcellText = tabcell as SortedList <int, SortedList <int, string> >; IGroupElement groupElementClass = new GroupElement() as IGroupElement; (groupElementClass as IElementProperties).Name = "表格"; (groupElementClass as IElementProperties).Type = "表格"; IEnvelope envelope1 = new Envelope() as IEnvelope; envelope1.XMin = Leftdown.X; envelope1.YMin = Leftdown.Y; envelope1.XMax = Leftdown.X + this.Width; envelope1.YMax = Leftdown.Y + this.Height; IEnvelope envelopeClass = envelope1 as IEnvelope; IEnvelope envelope = envelopeClass; IFillSymbol simpleFillSymbolClass = new SimpleFillSymbol(); (simpleFillSymbolClass as ISimpleFillSymbol).Style = esriSimpleFillStyle.esriSFSNull; IRectangleElement rectangleElement = new RectangleElement() as IRectangleElement; ((IElement)rectangleElement).Geometry = envelope; ((IFillShapeElement)rectangleElement).Symbol = simpleFillSymbolClass; IRectangleElement rectangleElementClass = rectangleElement as IRectangleElement; groupElementClass.AddElement(rectangleElement as IElement); IPoint pointClass = new Point() { X = Leftdown.X, Y = Leftdown.Y + this.Height }; IPoint point = pointClass; double height = this.Height / (double)this.RowNumber; double width = this.Width / (double)this.ColumnNumber; if (this.HasUpperBoundLine) { groupElementClass.AddElement(this.CreateHLine(point)); } if (this.HasLowerBoundLine) { groupElementClass.AddElement(this.CreateHLine(Leftdown)); } if (this.HasInnerHorizontalLine) { IPoint pointClass1 = new Point() { X = point.X, Y = point.Y - height }; y = pointClass1; groupElementClass.AddElement(this.CreateHLine(y)); if (!this.OnlyFirstHorizontalLine) { for (i = 0; i < this.RowNumber - 2; i++) { y.Y = y.Y - height; groupElementClass.AddElement(this.CreateHLine(y)); } } } if (this.HasLeftBoundLine) { groupElementClass.AddElement(this.CreateVLine(Leftdown)); } if (this.HasRightBoundLine) { IPoint pointClass2 = new Point() { X = Leftdown.X + this.Width, Y = Leftdown.Y }; groupElementClass.AddElement(this.CreateVLine(pointClass2)); } if (this.HasInnerVerticalLine) { IPoint pointClass3 = new Point() { X = Leftdown.X + width, Y = Leftdown.Y }; y = pointClass3; groupElementClass.AddElement(this.CreateVLine(y)); if (!this.OnlyFirstVerticalLine) { for (i = 0; i < this.ColumnNumber - 2; i++) { y.X = y.X + width; groupElementClass.AddElement(this.CreateVLine(y)); } } } IPoint pointClass4 = new Point() { X = point.X, Y = point.Y }; IPoint y1 = pointClass4; for (i = 0; i < this.RowNumber; i++) { IPoint pointClass5 = new Point() { X = y1.X, Y = y1.Y }; IPoint x = pointClass5; for (int j = 0; j < this.ColumnNumber; j++) { string cellText = this.GetCellText(i, j); if (cellText.Length > 0) { IElement element = this.CreateTabTextElement(pAV, cellText, x.X, x.Y - height / 2); groupElementClass.AddElement(element); this.SetTableCell(i, j, element); } x.X = x.X + width; } y1.Y = y1.Y - height; } this.m_pGroupElement = groupElementClass as IElement; }
public RegionControl(RectangleElement element) : this() { DataContext = element; }