Syncfusion AI Assistant

How can I help you?

PdfGraphics

21 Apr 202624 minutes to read

Represents a graphics from a PDF page.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
//Create a new pen.
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
//Draw line on the page graphics.
graphics.drawLine(pen, {x: 10, y: 10}, {x: 100, y: 100});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Properties

Get clientSize Size

Gets the size of the canvas reduced by margins and page templates (Read only).

Methods

drawArc

Draw arc on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Draw an arc on the page graphics
graphics.drawArc({x: 10, y: 20, width: 100, height: 200}, 20, 30, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle that defines the ellipse from which the arc shape comes.
startAngle number Angle measured in degrees clockwise from the x-axis to the first side of the arc shape.
sweepAngle number Angle measured in degrees clockwise from the startAngle parameter to the second side of the arc shape.
pen PdfPen Pen that determines the stroke color, width, and style of the arc.

Returns void

drawBezier

Draws a Bezier curve using a specified pen and coordinates for the start point, two control points, and end point.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Draw a Bezier curve on the page graphics
graphics.drawBezier({x: 50, y: 100}, {x: 200, y: 50}, {x: 100, y: 150}, {x: 150, y: 100}, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
start Point The (x, y) coordinates of the starting point of the Bezier curve.
first Point The (x, y) coordinates of the first control point of the Bezier curve.
second Point The (x, y) coordinates of the second control point of the Bezier curve.
end Point The (x, y) coordinates of the ending point of the Bezier curve.
pen PdfPen The pen that determines the stroke color, width, and style of the Bezier curve.

Returns void

drawEllipse

Draw ellipse on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Draw an ellipse on the page graphics
graphics.drawEllipse({x: 10, y: 20, width: 100, height: 200}, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle that defines the ellipse.
pen PdfPen Pen that determines the stroke color, width, and style of the ellipse.

Returns void

drawEllipse

Draw ellipse on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Draw an ellipse on the page graphics
graphics.drawEllipse({x: 10, y: 20, width: 100, height: 200}, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle that defines the ellipse.
brush PdfBrush Brush that determines the fill color and texture of the ellipse.

Returns void

drawEllipse

Draw ellipse on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Draw an ellipse on the page graphics
graphics.drawEllipse({x: 10, y: 20, width: 100, height: 200}, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle that defines the ellipse.
pen PdfPen Pen that determines the stroke color, width, and style of the ellipse.
brush PdfBrush Brush that determines the fill color and texture of the ellipse.

Returns void

drawImage

Draws an image on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new image object using JPEG image data as a Base64 string
let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
// Draw the image on the page graphics
graphics.drawImage(image, {x: 10, y: 20});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
image PdfImage The image to be drawn on the page.
location Point The (x, y) coordinates of the upper-left corner where the image will be drawn.

Returns void

drawImage

Draws an image on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new image object using JPEG image data as a Base64 string
let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
// Draw the image on the page graphics with specified width and height
graphics.drawImage(image, {x: 10, y: 20, width: 400, height: 400});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
image PdfImage The image to be drawn on the page.
bounds Rectangle The bounding rectangle that defines where the image will be drawn.

Returns void

drawLine

Draws a line on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Draw a line on the page graphics
graphics.drawLine(pen, {x: 10, y: 10}, {x: 100, y: 100});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
pen PdfPen The pen that determines the stroke color, width, and style of the line.
start Point The (x, y) coordinates of the starting point of the line.
end Point The (x, y) coordinates of the ending point of the line.

Returns void

drawPath

Draws a graphics path defined by a pen and path.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Create a new path
let path: PdfPath = new PdfPath();
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Add lines to the path
path.addLine({x: 10, y: 100}, {x: 50, y: 100});
path.addLine({x: 50, y: 100}, {x: 50, y: 150});
path.addLine({x: 50, y: 150}, {x: 10, y: 100});
// Draw the path on the page graphics
graphics.drawPath(path, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
path PdfPath The path to be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the path.

Returns void

drawPath

Draws a graphics path defined by a brush and path.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Create a new path
let path: PdfPath = new PdfPath();
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Add an ellipse to the path
path.addEllipse({x: 200, y: 200, width: 100, height: 50});
// Draw the path on the page graphics
graphics.drawPath(path, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
path PdfPath The path to be drawn.
brush PdfBrush The brush that determines the fill color and texture of the path.

Returns void

drawPath

Draws a graphics path defined by a pen, brush, and path.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Create a new path
let path: PdfPath = new PdfPath();
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Add an ellipse to the path
path.addEllipse({x: 200, y: 200, width: 100, height: 50});
// Draw the path on the page graphics with both pen and brush
graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
path PdfPath The path to be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the path.
brush PdfBrush The brush that determines the fill color and texture of the path.

Returns void

drawPie

Draws a pie slice on a PDF graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Draw a pie slice on the page graphics
graphics.drawPie({x: 10, y: 50, width: 200, height: 200}, 180, 60, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle.
startAngle number The angle in degrees measured clockwise from the x-axis to the start of the pie slice.
sweepAngle number The angle in degrees measured clockwise from the startAngle to the end of the pie slice.
pen PdfPen The pen that determines the stroke color, width, and style of the pie slice.

Returns void

drawPie

Draws a pie slice on PDF graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Draw a pie slice on the page graphics
graphics.drawPie({x: 10, y: 50, width: 200, height: 200}, 180, 60, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle.
startAngle number The angle in degrees, measured clockwise from the x-axis to the start of the pie slice.
sweepAngle number The angle in degrees, measured clockwise from the startAngle to the end of the pie slice.
brush PdfBrush The brush that determines the fill color and texture of the pie slice.

Returns void

drawPie

Draws a pie slice on PDF graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Draw a pie slice on the page graphics
graphics.drawPie({x: 10, y: 50, width: 200, height: 200}, 180, 60, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle.
startAngle number The angle in degrees, measured clockwise from the x-axis to the start of the pie slice.
sweepAngle number The angle in degrees, measured clockwise from the startAngle to the end of the pie slice.
pen PdfPen The pen that determines the stroke color, width, and style of the pie slice.
brush PdfBrush The brush that determines the fill color and texture of the pie slice.

Returns void

drawPolygon

Draw polygon on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Define the polygon points
let points: Point[] = [{x: 10, y: 100}, {x: 10, y: 200}, {x: 100, y: 100}, {x: 100, y: 200}, {x: 55, y: 150}];
// Draw the polygon on the page graphics
graphics.drawPolygon(points, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
points Point[] The points of the polygon.
pen PdfPen Pen that determines the stroke color, width, and style of the polygon.

Returns void

drawPolygon

Draw polygon on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Define the polygon points
let points: Point[] =[{x: 10, y: 100}, {x: 10, y: 200}, {x: 100, y: 100}, {x: 100, y: 200}, {x: 55, y: 150}];
// Draw the polygon on the page graphics
graphics.drawPolygon(points, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
points Point[] The points of the polygon.
brush PdfBrush Brush that determines the fill color and texture of the polygon.

Returns void

drawPolygon

Draw polygon on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Define the polygon points
let points: Point[] = [{x: 10, y: 100}, {x: 10, y: 200}, {x: 100, y: 100}, {x: 100, y: 200}, {x: 55, y: 150}];
// Draw the polygon on the page graphics
graphics.drawPolygon(points, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
points Point[] The points of the polygon.
pen PdfPen Pen that determines the stroke color, width, and style of the polygon.
brush PdfBrush Brush that determines the fill color and texture of the polygon.

Returns void

drawRectangle

Draw a rectangle on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen.
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Draw a rectangle on the page graphics.
graphics.drawRectangle({x: 10, y: 20, width: 100, height: 200}, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounds of the rectangular region.
pen PdfPen Pen that determines the stroke color, width, and style of the rectangle.

Returns void

drawRectangle

Draw a rectangle on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new brush.
let brush: PdfBrush = new PdfBrush({r: 0, g: 0, b: 255});
// Draw a filled rectangle on the page graphics.
graphics.drawRectangle({x: 10, y: 20, width: 100, height: 200}, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounds of the rectangular region.
brush PdfBrush Brush that determines the fill color and texture of the rectangle.

Returns void

drawRectangle

Draw a rectangle on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen.
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new brush.
let brush: PdfBrush = new PdfBrush({r: 0, g: 0, b: 255});
// Draw a rectangle with both stroke and fill on the page graphics.
graphics.drawRectangle({x: 10, y: 20, width: 100, height: 200}, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounds of the rectangular region.
pen PdfPen Pen that determines the stroke color, width, and style of the rectangle.
brush PdfBrush Brush that determines the fill color and texture of the rectangle.

Returns void

drawRoundedRectangle

Draws a rounded rectangle on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 0, b: 255});
// Draw a rounded rectangle on the page graphics
graphics.drawRoundedRectangle({x: 10, y: 20, width: 100, height: 200}, 5, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle of the rounded rectangle.
radius number The radius of the rounded corners of the rectangle.
pen PdfPen The pen that determines the stroke color, width, and style of the rectangle.
brush PdfBrush The brush that determines the fill color and texture of the rectangle.

Returns void

drawString

Draw text on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular);
// Draw text on the page graphics
graphics.drawString('Hello World', font, {x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
brush PdfBrush The brush that determines the fill color and texture of the string.

Returns void

drawString

Draw text on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular);
// Create a new string format
let format: PdfStringFormat = new PdfStringFormat();
format.alignment = PdfTextAlignment.center;
// Draw text on the page graphics
graphics.drawString('Hello World', font, {x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}), format);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
brush PdfBrush The brush that determines the fill color and texture of the string.
format PdfStringFormat The format that specifies text layout information such as alignment, line spacing, and trimming.

Returns void

drawString

Draw text on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular);
// Draw text on the page graphics
graphics.drawString('Hello World', font, {x: 10, y: 20, width: 100, height: 200}, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the string.

Returns void

drawString

Draw text on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular);
// Create a new string format
let format: PdfStringFormat = new PdfStringFormat();
format.alignment = PdfTextAlignment.center;
// Draw text on the page graphics
graphics.drawString('Hello World', font, {x: 10, y: 20, width: 100, height: 200}, pen, format);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the string.
format PdfStringFormat The format that specifies text layout information such as alignment, line spacing, and trimming.

Returns void

drawString

Draw text on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular);
// Draw text on the page graphics
graphics.drawString('Hello World', font, {x: 10, y: 20, width: 100, height: 200}, pen, new PdfBrush({r: 0, g: 0, b: 255}));
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the string.
brush PdfBrush The brush that determines the fill color and texture of the string.

Returns void

drawString

Draw text on the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
// Create a new font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular);
// Create a new string format
let format: PdfStringFormat = new PdfStringFormat();
format.alignment = PdfTextAlignment.center;
// Draw text on the page graphics
graphics.drawString('Hello World', font, {x: 10, y: 20, width: 100, height: 200}, pen, new PdfBrush({r: 0, g: 0, b: 255}), format);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the string.
brush PdfBrush The brush that determines the fill color and texture of the string.
format PdfStringFormat The format that specifies text layout information such as alignment, line spacing, and trimming.

Returns void

drawTemplate

Draws a PDF template onto the page graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the first annotation of the page
let annotation: PdfRubberStampAnnotation = page.annotations.at(0) as PdfRubberStampAnnotation;
// Gets the appearance template of the annotation
let template: PdfTemplate = annotation.createTemplate();
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Draw the template on the page graphics within the specified bounds
graphics.drawTemplate(template, { x: 10, y: 20, width: template.size.width, height: template.size.height });
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
template PdfTemplate The PDF template to be drawn.
bounds Rectangle The bounds of the template.

Returns void

restore

Restore the graphics state.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Save the graphics
let state: PdfGraphicsState = graphics.save();
//Set graphics translate transform.
graphics.translateTransform({x: 100, y: 100});
//Draws the String.
graphics.drawString('Hello world!', font, {x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
//Restore the graphics.
graphics.restore(state);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
state (optional) PdfGraphicsState graphics state.

Returns void

rotateTransform

Represents a rotate transform of the graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Save the current graphics state
let state: PdfGraphicsState = graphics.save();
// Apply rotate transform
graphics.rotateTransform(-90);
// Draw a string with the rotation applied
graphics.drawString('Hello world!', font, {x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
// Restore the graphics to its previous state
graphics.restore(state);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
angle number Angle of rotation in degrees.

Returns void

save

Save the current graphics state.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Save the graphics
let state: PdfGraphicsState = graphics.save();
//Set graphics translate transform.
graphics.translateTransform({x: 100, y: 100});
//Draws the String.
graphics.drawString('Hello world!', font, {x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
//Restore the graphics.
graphics.restore(state);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Returns PdfGraphicsState

scaleTransform

Represents a scale transform of the graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Save the current graphics state
let state: PdfGraphicsState = graphics.save();
// Apply scale transform
graphics.scaleTransform(0.5, 0.5);
// Draw a string with the scaled transformation
graphics.drawString('Hello world!', font, {x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
// Restore the graphics to its previous state
graphics.restore(state);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
scaleX number Scale factor in the x direction.
scaleY number Scale factor in the y direction.

Returns void

setClip

Represents a clipping region of this graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Set clipping region
graphics.setClip({x: 0, y: 0, width: 50, height: 12}, PdfFillMode.alternate);
// Draw a string within the clipping region
graphics.drawString('Hello world!', font, {x: 0, y: 0, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle Rectangle structure that represents the new clip region.
mode (optional) PdfFillMode Member of the PdfFillMode enumeration that specifies the filling operation to use.

Returns void

setTransparency

Represents a transparency of this graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Set transparency
graphics.setTransparency(0.5);
// Draw a string with transparency
graphics.drawString('Hello world!', font, {x: 0, y: 0, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
stroke number The transparency value for strokes.

Returns void

setTransparency

Represents a transparency setting for the graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Set transparency
graphics.setTransparency(0.5, 0.5, PdfBlendMode.multiply);
// Draw the string
graphics.drawString('Hello world!', font, {x: 0, y: 0, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
stroke number The transparency value for strokes.
fill number The transparency value for fills.
mode PdfBlendMode The blend mode to use.

Returns void

translateTransform

Represents a translate transform of the graphics.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new font
let font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 20, PdfFontStyle.regular);
// Save the current graphics state
let state: PdfGraphicsState = graphics.save();
// Apply translate transform
graphics.translateTransform({x: 100, y: 100});
// Draw a string with the translation applied
graphics.drawString('Hello world!', font, {x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
// Restore the graphics to its previous state
graphics.restore(state);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
location Point (x, y) coordinates of the translation.

Returns void