Pdf Graphic Elements | |
Select.Pdf has support to draw a variety of shapes, such as:
Circles: PdfCircleElement
Ellipses: PdfEllipseElement
Ellipse Slices: PdfEllipseSliceElement
Ellipse Arcs: PdfEllipseArcElement
Lines: PdfLineElement
Polygons: PdfPolygonElement
Rectangles: PdfRectangleElement
Bezier Curves: PdfBezierCurveElement
These graphic elements (all derived from PdfElement), share a number of properties that can be used to modify their appearance:
Line style: LineStyle can be used to specify the line styles of the graphic elements that draw lines. Using this, the line width, line dash style, line cap style and line join style can be specified.
Gradient: Gradient can be used to specify the gradient used to fill a shape.
Line color: ForeColor can be used to specify the color of the drawn lines.
Background color: BackColor can be used to specify the background color.
Color space: ColorSpace can be used to write the colors of the element in RGB (the default), CMYK or grayscale.
The following code shows how to draw several graphic elements:
// create a new pdf document PdfDocument doc = new PdfDocument(); // add a new page to the document PdfPage page = doc.AddPage(); // define a rendering result object PdfRenderingResult result; // simple horizontal line element PdfLineElement line1 = new PdfLineElement(0, 0, 400, 0); line1.LineStyle.LineWidth = 3; result = page.Add(line1); // horizontal dotted red line element PdfLineElement line2 = new PdfLineElement(0, 30, 400, 30); line2.ForeColor = new PdfColor(255, 0, 0); line2.LineStyle.LineWidth = 2; line2.LineStyle.LineDashStyle = PdfLineDashStyle.Dot; result = page.Add(line2); // horizontal dashed blue line element with complex styles PdfLineElement line3 = new PdfLineElement(0, 60, 400, 60); line3.ForeColor = new PdfColor(0, 0, 255); line3.LineStyle.LineWidth = 2; line3.LineStyle.LineDashStyle = PdfLineDashStyle.Dash; line3.LineStyle.LineCapStyle = PdfLineCapStyle.RoundCap; line3.LineStyle.LineJoinStyle = PdfLineJoinStyle.RoundJoin; result = page.Add(line3); // simple rectangle PdfRectangleElement rect1 = new PdfRectangleElement(0, 90, 400, 100); result = page.Add(rect1); // simple circle PdfCircleElement circ1 = new PdfCircleElement(50, 250, 50); circ1.ForeColor = new PdfColor(0, 128, 0); result = page.Add(circ1); // ellipse filled with gradient background color PdfEllipseElement elli1 = new PdfEllipseElement(300, 250, 100, 50); elli1.ForeColor = new PdfColor(165, 42, 42); elli1.Gradient = new PdfGradient(new PdfColor(173, 216, 230), new PdfColor(0, 0, 139), PdfGradientDirection.ForwardDiagonal); elli1.LineStyle.LineWidth = 2; result = page.Add(elli1); // bezier curve PdfBezierCurveElement bez1 = new PdfBezierCurveElement( 50, 350, 100, 400, 200, 350, 250, 370); result = page.Add(bez1); // save pdf document doc.Save("Sample.pdf"); // close pdf document doc.Close();