- Solid Brush
- Linear gradient brush
- Radial Gradient Brush
- Tiling Brush
- Hatch Brush
Contact Support
Working with Brushes
26 Mar 202515 minutes to read
Brushes are used to draw the content on PDF document with specific color and style. Various brushes available in Syncfusion Essential® PDF are,
- Solid Brush
- Gradient Brush
- Linear Gradient Brush
- Radial Gradient Brush
- Tiling Brush
- Hatch Brush
Solid Brush
The solid brush is used to fill an object with solid color. Essential® PDF supports drawing shapes on PDF document with solid brush using the PdfSolidBrush class. The following code snippet illustrates this.
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF solid brush
PdfSolidBrush brush = new PdfSolidBrush(Color.Red);
//Draw ellipse on the page
graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100));
//Save the PDF document to stream
MemoryStream stream = new MemoryStream();
doc.Save(stream);
//Close the Pdf Document
doc.Close(true);
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF solid brush
PdfSolidBrush brush = new PdfSolidBrush(Color.Red);
//Draw ellipse on the page
graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100));
//Save the PDF document
doc.Save("SolidBrush.pdf");
//Close the instance of PdfDocument
doc.Close(true);
'Create a new PDF document
Dim doc As PdfDocument = New PdfDocument
'Add a page to the document
Dim page As PdfPage = doc.Pages.Add
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF solid brush
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Red)
'Draw ellipse on the page
graphics.DrawEllipse(brush, New RectangleF(0, 0, 200, 100))
'Save the PDF document
doc.Save("SolidBrush.pdf")
'Close the instance of PdfDocument
doc.Close(True)
You can download a complete working sample from GitHub.
Linear gradient brush
The gradient brush is used to fill an object with blend of two or more colors. Essential® PDF supports drawing shapes on PDF document with linear gradient brush using PdfLinearGradientBrush class. The following code snippet illustrates this.
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF linear gradient brush
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Draw ellipse on the page
graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100));
//Save the PDF document to stream
MemoryStream stream = new MemoryStream();
doc.Save(stream);
//Close the Pdf Document
doc.Close(true);
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF linear gradient brush
PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue);
//Draw ellipse on the page
graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100));
//Save the PDF document
doc.Save("LinearGradientBrush.pdf");
//Close the instance of PdfDocument
doc.Close(true);
'Create a new PDF document
Dim doc As PdfDocument = New PdfDocument
'Add a page to the document
Dim page As PdfPage = doc.Pages.Add
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF linear gradient brush
Dim brush As PdfLinearGradientBrush = New PdfLinearGradientBrush(New PointF(0, 0), New PointF(200, 100), Color.Red, Color.Blue)
'Draw ellipse on the page
graphics.DrawEllipse(brush, New RectangleF(0, 0, 200, 100))
'Save the PDF document
doc.Save("LinearGradientBrush.pdf")
'Close the instance of PdfDocument
doc.Close(True)
You can download a complete working sample from GitHub.
Radial Gradient Brush
The gradient brush is used to fill an object with blend of two or more colors. You can draw any shape on PDF document with radial gradient brush using PdfRadialGradientBrush class. The following code snippet explains this.
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF radial gradient brush
PdfRadialGradientBrush brush = new PdfRadialGradientBrush(new PointF(50, 50), 0, new PointF(50, 50), 50, Color.Red, Color.Blue);
//Draw ellipse on the page
graphics.DrawEllipse(brush, new RectangleF(0, 0, 100, 100));
//Save the PDF document stream
MemoryStream stream = new MemoryStream();
doc.Save(stream);
//Close the Pdf Document
doc.Close(true);
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF radial gradient brush
PdfRadialGradientBrush brush = new PdfRadialGradientBrush(new PointF(50, 50), 0, new PointF(50, 50), 50, Color.Red, Color.Blue);
//Draw ellipse on the page
graphics.DrawEllipse(brush, new RectangleF(0, 0, 100, 100));
//Save the PDF document
doc.Save("RadialGradientBrush.pdf");
//Close the instance of PdfDocument
doc.Close(true);
'Create a new PDF document
Dim doc As PdfDocument = New PdfDocument
'Add a page to the document
Dim page As PdfPage = doc.Pages.Add
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF radial gradient brush
Dim brush As PdfRadialGradientBrush = New PdfRadialGradientBrush(New PointF(50, 50), 0, New PointF(50, 50), 50, Color.Red, Color.Blue)
'Draw ellipse on the page
graphics.DrawEllipse(brush, New RectangleF(0, 0, 100, 100))
'Save the PDF document
doc.Save("RadialGradientBrush.pdf")
'Close the instance of PdfDocument
doc.Close(True)
You can download a complete working sample from GitHub.
Tiling Brush
The tiling brush is used to draw an object repeatedly. You can draw any shape on PDF page with tiling brush using PdfTilingBrush class. The following code snippet explains this.
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF tiling brush
PdfTilingBrush brush = new PdfTilingBrush(new RectangleF(0, 0, 11, 11));
//Draw ellipse inside the tile
brush.Graphics.DrawEllipse(PdfPens.Red, new RectangleF(0, 0, 10, 10));
//Draw ellipse
graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100));
//Save the PDF document to stream
MemoryStream stream = new MemoryStream();
doc.Save(stream);
//Close the Pdf Document
doc.Close(true);
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create new PDF tiling brush
PdfTilingBrush brush = new PdfTilingBrush(new RectangleF(0, 0, 11, 11));
//Draw ellipse inside the tile
brush.Graphics.DrawEllipse(PdfPens.Red, new RectangleF(0, 0, 10, 10));
//Draw ellipse
graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100));
//Save the PDF document
doc.Save("TilingBrush.pdf");
//Close the instance of PdfDocument
doc.Close(true);
'Create a new PDF document
Dim doc As PdfDocument = New PdfDocument
'Add a page to the document
Dim page As PdfPage = doc.Pages.Add
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create new PDF tiling brush
Dim brush As PdfTilingBrush = New PdfTilingBrush(New RectangleF(0, 0, 11, 11))
'Draw ellipse inside the tile
brush.Graphics.DrawEllipse(PdfPens.Red, New RectangleF(0, 0, 10, 10))
'Draw ellipse
graphics.DrawEllipse(brush, New RectangleF(0, 0, 200, 100))
'Save the PDF document
doc.Save("TilingBrush.pdf")
'Close the instance of PdfDocument
doc.Close(True)
You can download a complete working sample from GitHub.
Hatch Brush
The hatch brush is used to fill an object with hatch patterns. Essential® PDF supports drawing shapes in a PDF document using a hatch brush with the PdfHatchBrush class. The following code example illustrates this.
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Define colors for the hatch brush
Color systemForeColor = Color.FromArgb(255, 255, 255, 0);
Color systemBackColor = Color.FromArgb(255, 78, 167, 46);
// Create a new PDF hatch brush with a pattern and colors
PdfHatchBrush pdfHatchBrush = new PdfHatchBrush(PdfHatchStyle.Plaid, new PdfColor(systemForeColor), new PdfColor(systemBackColor));
//Draw rectangle on the page
graphics.DrawRectangle(PdfPens.Black, pdfHatchBrush, new Rectangle(100, 100, 300, 200));
//Save the PDF document to stream
MemoryStream stream = new MemoryStream();
doc.Save(stream);
//Close the Pdf Document
doc.Close(true);
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Define colors for the hatch brush
Color systemForeColor = Color.FromArgb(255, 255, 255, 0);
Color systemBackColor = Color.FromArgb(255, 78, 167, 46);
// Create a new PDF hatch brush with a pattern and colors
PdfHatchBrush pdfHatchBrush = new PdfHatchBrush(PdfHatchStyle.Plaid, new PdfColor(systemForeColor), new PdfColor(systemBackColor));
//Draw rectangle on the page
graphics.DrawRectangle(PdfPens.Black, pdfHatchBrush, new Rectangle(100, 100, 300, 200));
//Save the PDF document
doc.Save("Output.pdf");
//Close the Pdf Document
doc.Close(true);
' Create a new PDF document
Dim doc As PdfDocument = New PdfDocument
' Add a page to the document
Dim page As PdfPage = doc.Pages.Add
' Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
' Define colors for the hatch brush
Dim systemForeColor As Color = Color.FromArgb(255, 255, 255, 0)
Dim systemBackColor As Color = Color.FromArgb(255, 78, 167, 46)
' Create a new PDF hatch brush with a pattern and colors
Dim pdfHatchBrush As PdfHatchBrush = New PdfHatchBrush(PdfHatchStyle.Plaid, New PdfColor(systemForeColor), New PdfColor(systemBackColor))
' Draw rectangle on the page
graphics.DrawRectangle(PdfPens.Black, pdfHatchBrush, New Rectangle(100, 100, 300, 200))
' Save the PDF document
doc.Save("Output.pdf")
' Close the PDF document
doc.Close(True)
You can download a complete working sample from GitHub.