π¨ Vector Graphics
Lines, shapes, BΓ©zier paths, dash patterns, and alpha transparency.
C# β Vector Graphics
// Lines with different styles
page.DrawLine(72, 700, 250, 700); // Solid
page.DrawLine(72, 680, 250, 680, new PdfDrawOptions {
DashPattern = new[] { 8.0, 4.0 },
StrokeColor = new PdfColor(0, 0, 0.7)
});
// Shapes
page.FillRectangle(100, 600, 80, 50,
new PdfDrawOptions {
FillColor = new PdfColor(0.2, 0.5, 0.8)
});
page.FillCircle(220, 560, 30,
new PdfDrawOptions {
FillColor = new PdfColor(0, 0.7, 0.3)
});
// Polygon (triangle)
page.FillPolygon(new[] {
(100.0, 440.0), (150.0, 500.0), (200.0, 440.0)
}, new PdfDrawOptions {
FillColor = new PdfColor(1.0, 0.5, 0.0)
});
// BΓ©zier curve path
page.BeginPath(new PdfDrawOptions {
FillColor = new PdfColor(0.3, 0.3, 0.8),
LineWidth = 1.5
})
.MoveTo(300, 440)
.CurveTo(420, 520, 440, 480, 420, 440)
.ClosePath()
.FillAndStroke();
// Transparent overlapping circles
page.SaveGraphicsState();
page.SetAlpha(fillAlpha: 0.5);
page.FillCircle(140, 350, 40,
new PdfDrawOptions {
FillColor = new PdfColor(1, 0, 0) });
page.FillCircle(170, 350, 40,
new PdfDrawOptions {
FillColor = new PdfColor(0, 1, 0) });
page.FillCircle(155, 380, 40,
new PdfDrawOptions {
FillColor = new PdfColor(0, 0, 1) });
page.RestoreGraphicsState();
You should see (top to bottom): a solid black line and a dashed blue line; a blue filled rectangle and a green filled circle; an orange triangle; a closed blue BΓ©zier shape; and three overlapping semi-transparent red, green, and blue circles showing alpha blending.
File: 04_vector_graphics.pdf
Drawing Methods
| Method | Description |
|---|---|
DrawLine() | Line between two points |
DrawRectangle() / FillRectangle() | Rectangle outline / filled |
DrawCircle() / FillCircle() | Circle outline / filled |
DrawEllipse() / FillEllipse() | Ellipse outline / filled |
DrawPolygon() / FillPolygon() | Polygon outline / filled |
BeginPath() | Start custom path (lines, curves) |
SetAlpha() | Set stroke/fill transparency (0.0β1.0) |