Shape Elements |
The document model defines the following shape elements:
The outline of a shape is drawn with the ForeColor color and the LineStyle line style, and a closed shape is filled with the BackColor color or the Gradient gradient. The colors are PdfColor objects: an Color converts to one implicitly, and the PdfColor constructors also take RGB, CMYK or gray values.
Below is a sample code showing how to add shapes to a PDF document:
// add a page to the PDF document PdfPage firstPage = document.AddPage(); // draw rectangle RectangleElement rectangle1 = new RectangleElement(10, 10, 150, 100); rectangle1.ForeColor = Color.Blue; rectangle1.LineStyle.LineWidth = 5; rectangle1.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin; firstPage.AddElement(rectangle1); // draw colored rectangle RectangleElement rectangle2 = new RectangleElement(200, 10, 150, 100); rectangle2.ForeColor = Color.Blue; rectangle2.BackColor = Color.Green; firstPage.AddElement(rectangle2); // draw gradient colored rectangle RectangleElement rectangle3 = new RectangleElement(400, 25, 100, 50); rectangle3.ForeColor = Color.Blue; rectangle3.Gradient = new GradientColor(GradientDirection.Vertical, Color.Green, Color.Blue); firstPage.AddElement(rectangle3); // draw ellipse EllipseElement ellipse1 = new EllipseElement(75, 200, 70, 50); ellipse1.ForeColor = Color.Blue; ellipse1.LineStyle.LineDashStyle = LineDashStyle.Dash; firstPage.AddElement(ellipse1); // draw filled ellipse EllipseElement ellipse2 = new EllipseElement(275, 200, 70, 50); ellipse2.ForeColor = Color.Blue; ellipse2.BackColor = Color.Green; firstPage.AddElement(ellipse2); // draw circle filled with a gradient CircleElement circle1 = new CircleElement(450, 200, 40); circle1.ForeColor = Color.Blue; circle1.Gradient = new GradientColor(GradientDirection.Vertical, Color.Green, Color.Blue); firstPage.AddElement(circle1); // draw Bezier curves BezierCurveElement bezierCurve1 = new BezierCurveElement(10, 350, 100, 300, 200, 400, 300, 350); bezierCurve1.ForeColor = 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 = Color.Green; bezierCurve2.LineStyle.LineWidth = 3; bezierCurve2.LineStyle.LineJoinStyle = LineJoinStyle.RoundJoin; firstPage.AddElement(bezierCurve2); // draw a filled triangle PolygonElement triangle = new PolygonElement(new PointF[] { new PointF(400, 300), new PointF(500, 300), new PointF(450, 400) }); triangle.ForeColor = Color.Blue; triangle.BackColor = Color.FromArgb(255, 200, 0); firstPage.AddElement(triangle);