@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
2,772 lines • 105 kB
TypeScript
import { PdfPage } from './../pdf-page';
import { _PdfStreamWriter } from './pdf-stream-writer';
import { _PdfContentStream } from './../base-stream';
import { _PdfDictionary, _PdfReference, _PdfName } from './../pdf-primitives';
import { _PdfCrossReference } from './../pdf-cross-reference';
import { PdfFont, PdfTrueTypeFont } from './../fonts/pdf-standard-font';
import { _PdfStringLayouter, _PdfStringLayoutResult, _LineInfo } from './../fonts/string-layouter';
import { _PdfGraphicsUnit, PdfBlendMode, PdfLineJoin, PdfLineCap, PdfDashStyle, PdfFillMode, PathPointType } from './../enumerator';
import { PdfStringFormat } from './../fonts/pdf-string-format';
import { PdfTemplate } from './pdf-template';
import { PdfPath } from './pdf-path';
import { PdfImage } from './images/pdf-image';
import { PdfLayer } from '../layers/layer';
import { Rectangle, Point, Size, PdfColor } from '../pdf-type';
import { PdfTextElement } from '../pdf-type';
/**
* Represents a graphics from a PDF page.
* ```typescript
* // 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();
* ```
*/
export declare class PdfGraphics {
/**
* Source dictionary for page or template resources.
*
* @private
*/
_source: _PdfDictionary;
/**
* Stream writer for page or template resources.
*
* @private
*/
_sw: _PdfStreamWriter;
/**
* Stream writer used to emit content operators into the page then rendering this graphics.
*
* @private
*/
_cropBox: Array<number>;
/**
* Upper-right bound value of the media box for layout calculations.
*
* @private
*/
_mediaBoxUpperRightBound: number;
/**
* Cached transformation matrix for the graphics context.
*
* @private
*/
_m: _PdfTransformationMatrix;
/**
* Current character spacing used for text rendering.
*
* @private
*/
_characterSpacing: number;
/**
* Current word spacing used for text rendering.
*
* @private
*/
_wordSpacing: number;
/**
* Horizontal text scaling factor.
*
* @private
*/
_textScaling: number;
/**
* Current text rendering mode (fill/stroke/clip options).
*
* @private
*/
_textRenderingMode: _TextRenderingMode;
/**
* Stack of saved graphics states for nested save/restore.
*
* @private
*/
_graphicsState: PdfGraphicsState[];
/**
* Client size of the graphics surface.
*
* @private
*/
_size: Size;
/**
* Current clipping bounds as [x, y, width, height].
*
* @private
*/
_clipBounds: number[];
/**
* Local resources dictionary for the page or template.
*
* @private
*/
_resourceObject: _PdfDictionary;
/**
* Mapping of resource references to their local resource names.
*
* @private
*/
_resourceMap: Map<_PdfReference, _PdfName>;
/**
* Cross-reference table used to resolve and cache indirect objects.
*
* @private
*/
_crossReference: _PdfCrossReference;
/**
* Cache of transparency settings keyed by computed identifier.
*
* @private
*/
_transparencies: Map<_TransparencyData, string>;
/**
* Indicates whether resources are stored by reference on the page/template.
*
* @private
*/
_hasResourceReference: boolean;
/**
* Currently selected pen for stroking operations.
*
* @private
*/
_currentPen: PdfPen;
/**
* Currently selected brush for filling operations.
*
* @private
*/
_currentBrush: PdfBrush;
/**
* Currently selected font used for drawing text.
*
* @private
*/
_currentFont: any;
/**
* Tracks whether color spaces have been initialized for resources.
*
* @private
*/
_colorSpaceInitialized: boolean;
/**
* Index used internally when handling cut/trim operations.
*
* @private
*/
_startCutIndex: number;
/**
* Owning `PdfPage` when this graphics is associated with a page.
*
* @private
*/
_page: PdfPage;
/**
* Owning `PdfTemplate` when this graphics is rendering a template.
*
* @private
*/
_template: PdfTemplate;
/**
* True when this graphics instance belongs to a template rather than a page.
*
* @private
*/
_isTemplateGraphics: boolean;
/**
* Current top-level graphics state object.
*
* @private
*/
_state: PdfGraphicsState;
/**
* Resources waiting to be written into the cross-reference when saving.
*
* @private
*/
_pendingResource: any[];
/**
* Indicates whether italic text style is active.
*
* @private
*/
_isItalic: boolean;
/**
* Indicates whether the associated layer contains no drawing content.
*
* @private
*/
_isEmptyLayer: boolean;
/**
* Current layer used for layered content operations.
*
* @private
*/
_layer: PdfLayer;
/**
* Indicates whether the current graphics context is in layouter mode.
*
* @private
*/
_isLayouter: boolean;
/**
* Cached string layouter reused across drawString calls.
*
* @private
*/
_stringLayouter: _PdfStringLayouter;
/**
* Lazily creates and returns the current graphics transformation matrix.
*
* @private
* @returns {_PdfTransformationMatrix} The current transformation matrix.
*/
readonly _matrix: _PdfTransformationMatrix;
/**
* Builds and returns the local resource name map by scanning page/template resources
* Populates transparency cache when available.
*
* @private
* @returns {Map<_PdfReference, _PdfName>} The mapping of references to resource names.
*/
readonly _resources: Map<_PdfReference, _PdfName>;
/**
* Gets the size of the canvas reduced by margins and page templates (Read only).
*
* @returns {Size} The width and height of the client area as number array.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Access first page
* let page: PdfPage = document.getPage(0);
* // Gets the graphics client size.
* let size: Size = page.graphics.clientSize;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
readonly clientSize: Size;
/**
* Initializes a new instance of the `PdfGraphics` class.
*
* @param {Size} size The graphics client size.
* @param {_PdfContentStream} content Content stream.
* @param {_PdfCrossReference} xref Cross reference.
* @param {PdfPage | PdfTemplate} source Source object of the graphics.
* @private
*/
constructor(size: Size, content: _PdfContentStream, xref: _PdfCrossReference, source: PdfPage | PdfTemplate);
/**
* Save the current graphics state.
*
* ```typescript
* // 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} graphics state.
*/
save(): PdfGraphicsState;
/**
* Restore the graphics state.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfGraphicsState} state graphics state.
* @returns {void} restore of the graphics state.
*/
restore(state?: PdfGraphicsState): void;
/**
* Represents a scale transform of the graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {number} scaleX Scale factor in the x direction.
* @param {number} scaleY Scale factor in the y direction.
* @returns {void} Nothing.
*/
scaleTransform(scaleX: number, scaleY: number): void;
/**
* Represents a translate transform of the graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Point} location (x, y) coordinates of the translation.
* @returns {void} Nothing.
*/
translateTransform(location: Point): void;
/**
* Represents a rotate transform of the graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {number} angle Angle of rotation in degrees.
* @returns {void} Nothing.
*/
rotateTransform(angle: number): void;
/**
* Represents a clipping region of this graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds Rectangle structure that represents the new clip region.
* @param {PdfFillMode} mode Member of the PdfFillMode enumeration that specifies the filling operation to use.
* @returns {void} Nothing.
*/
setClip(bounds: Rectangle, mode?: PdfFillMode): void;
/**
* Represents a transparency of this graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {number} stroke The transparency value for the stroke.
* @returns {void} Nothing.
*/
setTransparency(stroke: number): void;
/**
* Represents a transparency setting for the graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {number} stroke The transparency value for strokes.
* @param {number} fill The transparency value for fills.
* @param {PdfBlendMode} mode The blend mode to use.
* @returns {void} Nothing.
*/
setTransparency(stroke: number, fill: number, mode: PdfBlendMode): void;
/**
* Draws a line on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the line.
* @param {Point} start The (x, y) coordinates of the starting point of the line.
* @param {Point} end The (x, y) coordinates of the ending point of the line.
* @returns {void} Nothing.
*/
drawLine(pen: PdfPen, start: Point, end: Point): void;
/**
* Draw a rectangle on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounds of the rectangular region.
* @param {PdfPen} pen Pen that determines the stroke color, width, and style of the rectangle.
*/
drawRectangle(bounds: Rectangle, pen: PdfPen): void;
/**
* Draw a rectangle on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounds of the rectangular region.
* @param {PdfBrush} brush Brush that determines the fill color and texture of the rectangle.
* @returns {void} Nothing
*/
drawRectangle(bounds: Rectangle, brush: PdfBrush): void;
/**
* Draw a rectangle on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounds of the rectangular region.
* @param {PdfPen} pen Pen that determines the stroke color, width, and style of the rectangle.
* @param {PdfBrush} brush Brush that determines the fill color and texture of the rectangle.
* @returns {void} Nothing
*/
drawRectangle(bounds: Rectangle, pen: PdfPen, brush: PdfBrush): void;
/**
* Draws a Bezier curve using a specified pen and coordinates for the start point, two control points, and end point.
*
* ```typescript
* // 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();
* ```
*
* @param {Point} start The (x, y) coordinates of the starting point of the Bezier curve.
* @param {Point} first The (x, y) coordinates of the first control point of the Bezier curve.
* @param {Point} second The (x, y) coordinates of the second control point of the Bezier curve.
* @param {Point} end The (x, y) coordinates of the ending point of the Bezier curve.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the Bezier curve.
* @returns {void} Nothing
*/
drawBezier(start: Point, first: Point, second: Point, end: Point, pen: PdfPen): void;
/**
* Draws a pie slice on a PDF graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounding rectangle.
* @param {number} startAngle The angle in degrees measured clockwise from the x-axis to the start of the pie slice.
* @param {number} sweepAngle The angle in degrees measured clockwise from the startAngle to the end of the pie slice.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the pie slice.
* @returns {void} Nothing
*/
drawPie(bounds: Rectangle, startAngle: number, sweepAngle: number, pen: PdfPen): void;
/**
* Draws a pie slice on PDF graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounding rectangle.
* @param {number} startAngle The angle in degrees, measured clockwise from the x-axis to the start of the pie slice.
* @param {number} sweepAngle The angle in degrees, measured clockwise from the startAngle to the end of the pie slice.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the pie slice.
* @returns {void} Nothing
*/
drawPie(bounds: Rectangle, startAngle: number, sweepAngle: number, brush: PdfBrush): void;
/**
* Draws a pie slice on PDF graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounding rectangle.
* @param {number} startAngle The angle in degrees, measured clockwise from the x-axis to the start of the pie slice.
* @param {number} sweepAngle The angle in degrees, measured clockwise from the startAngle to the end of the pie slice.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the pie slice.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the pie slice.
* @returns {void} Nothing
*/
drawPie(bounds: Rectangle, startAngle: number, sweepAngle: number, pen: PdfPen, brush: PdfBrush): void;
/**
* Draw polygon on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Point[]} points The points of the polygon.
* @param {PdfPen} pen Pen that determines the stroke color, width, and style of the polygon.
* @returns {void} Nothing.
*/
drawPolygon(points: Point[], pen: PdfPen): void;
/**
* Draw polygon on the page graphics.
*
*```typescript
* // 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();
* ```
*
* @param {Point[]} points The points of the polygon.
* @param {PdfBrush} brush Brush that determines the fill color and texture of the polygon.
* @returns {void} Nothing
*/
drawPolygon(points: Point[], brush: PdfBrush): void;
/**
* Draw polygon on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Point[]} points The points of the polygon.
* @param {PdfPen} pen Pen that determines the stroke color, width, and style of the polygon.
* @param {PdfBrush} brush Brush that determines the fill color and texture of the polygon.
* @returns {void} Nothing.
*/
drawPolygon(points: Point[], pen: PdfPen, brush: PdfBrush): void;
/**
* Draw ellipse on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounding rectangle that defines the ellipse.
* @param {PdfPen} pen Pen that determines the stroke color, width, and style of the ellipse.
* @returns {void} Nothing.
*/
drawEllipse(bounds: Rectangle, pen: PdfPen): void;
/**
* Draw ellipse on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounding rectangle that defines the ellipse.
* @param {PdfBrush} brush Brush that determines the fill color and texture of the ellipse.
* @returns {void} Nothing.
*/
drawEllipse(bounds: Rectangle, brush: PdfBrush): void;
/**
* Draw ellipse on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounding rectangle that defines the ellipse.
* @param {PdfPen} pen Pen that determines the stroke color, width, and style of the ellipse.
* @param {PdfBrush} brush Brush that determines the fill color and texture of the ellipse.
* @returns {void} Nothing.
*/
drawEllipse(bounds: Rectangle, pen: PdfPen, brush: PdfBrush): void;
/**
* Draw arc on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounding rectangle that defines the ellipse from which the arc shape comes.
* @param {number} startAngle Angle measured in degrees clockwise from the x-axis to the first side of the arc shape.
* @param {number} sweepAngle Angle measured in degrees clockwise from the startAngle parameter to the second side of the arc shape.
* @param {PdfPen} pen Pen that determines the stroke color, width, and style of the arc.
* @returns {void} Nothing.
*/
drawArc(bounds: Rectangle, startAngle: number, sweepAngle: number, pen: PdfPen): void;
/**
* Draws an image on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfImage} image The image to be drawn on the page.
* @param {Point} location The (x, y) coordinates of the upper-left corner where the image will be drawn.
* @returns {void} Nothing.
*/
drawImage(image: PdfImage, location: Point): void;
/**
* Draws an image on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfImage} image The image to be drawn on the page.
* @param {Rectangle} bounds The bounding rectangle that defines where the image will be drawn.
* @returns {void} Nothing.
*/
drawImage(image: PdfImage, bounds: Rectangle): void;
/**
* Draws a PDF template onto the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfTemplate} template The PDF template to be drawn.
* @param {Rectangle} bounds The bounds of the template.
* @returns {void} Nothing.
*/
drawTemplate(template: PdfTemplate, bounds: Rectangle): void;
/**
* Draws a graphics path defined by a pen and path.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfPath} path The path to be drawn.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the path.
* @returns {void} Nothing.
*/
drawPath(path: PdfPath, pen: PdfPen): void;
/**
* Draws a graphics path defined by a brush and path.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfPath} path The path to be drawn.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the path.
* @returns {void} Nothing.
*/
drawPath(path: PdfPath, brush: PdfBrush): void;
/**
* Draws a graphics path defined by a pen, brush, and path.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfPath} path The path to be drawn.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the path.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the path.
* @returns {void} Nothing.
*/
drawPath(path: PdfPath, pen: PdfPen, brush: PdfBrush): void;
/**
* Draws a rounded rectangle on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {Rectangle} bounds The bounding rectangle of the rounded rectangle.
* @param {number} radius The radius of the rounded corners of the rectangle.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the rectangle.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the rectangle.
* @returns {void} Nothing.
*/
drawRoundedRectangle(bounds: Rectangle, radius: number, pen: PdfPen, brush: PdfBrush): void;
/**
* Draw text on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {string} value The string to be drawn.
* @param {PdfFont} font The font used to draw the string.
* @param {Rectangle} bounds The rectangle specifying the bounds where the string will be drawn.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the string.
* @returns {void} Nothing.
*/
drawString(value: string, font: PdfFont, bounds: Rectangle, brush: PdfBrush): void;
/**
* Draw text on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {string} value The string to be drawn.
* @param {PdfFont} font The font used to draw the string.
* @param {Rectangle} bounds The rectangle specifying the bounds where the string will be drawn.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the string.
* @param {PdfStringFormat} format The format that specifies text layout information such as alignment, line spacing, and trimming.
* @returns {void} Nothing.
*/
drawString(value: string, font: PdfFont, bounds: Rectangle, brush: PdfBrush, format: PdfStringFormat): void;
/**
* Draw text on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {string} value The string to be drawn.
* @param {PdfFont} font The font used to draw the string.
* @param {Rectangle} bounds The rectangle specifying the bounds where the string will be drawn.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the string.
* @returns {void} Nothing.
*/
drawString(value: string, font: PdfFont, bounds: Rectangle, pen: PdfPen): void;
/**
* Draw text on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {string} value The string to be drawn.
* @param {PdfFont} font The font used to draw the string.
* @param {Rectangle} bounds The rectangle specifying the bounds where the string will be drawn.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the string.
* @param {PdfStringFormat} format The format that specifies text layout information such as alignment, line spacing, and trimming.
* @returns {void} Nothing.
*/
drawString(value: string, font: PdfFont, bounds: Rectangle, pen: PdfPen, format: PdfStringFormat): void;
/**
* Draw text on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {string} value The string to be drawn.
* @param {PdfFont} font The font used to draw the string.
* @param {Rectangle} bounds The rectangle specifying the bounds where the string will be drawn.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the string.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the string.
* @returns {void} Nothing.
*/
drawString(value: string, font: PdfFont, bounds: Rectangle, pen: PdfPen, brush: PdfBrush): void;
/**
* Draw text on the page graphics.
*
* ```typescript
* // 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();
* ```
*
* @param {string} value The string to be drawn.
* @param {PdfFont} font The font used to draw the string.
* @param {Rectangle} bounds The rectangle specifying the bounds where the string will be drawn.
* @param {PdfPen} pen The pen that determines the stroke color, width, and style of the string.
* @param {PdfBrush} brush The brush that determines the fill color and texture of the string.
* @param {PdfStringFormat} format The format that specifies text layout information such as alignment, line spacing, and trimming.
* @returns {void} Nothing.
*/
drawString(value: string, font: PdfFont, bounds: Rectangle, pen: PdfPen, brush: PdfBrush, format: PdfStringFormat): void;
/**
* Draws a text element on the graphics context at a given location.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Access the first page of the document
* let page: PdfPage = document.getPage(0);
* // Create a text element
* let element: PdfTextElement = {
* text: 'Hello world drawn using a point location.',
* font: document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular),
* brush: new PdfBrush({ r: 0, g: 0, b: 0 })
* };
* // Draw the text element using a specific point
* page.graphics.drawTextElement(element, { x: 50, y: 100 });
* // Save the PDF document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*
* @param {PdfTextElement} element The text element to draw.
* @param {Point} location The location where the text element should be drawn.
* @returns {void} Nothing.
*/
drawTextElement(element: PdfTextElement, location: Point): void;
/**
* Draws a text element inside a rectangle on the graphics context.
*
* ```typescript
* // Load an existing PDF document
* let document: PdfDocument = new PdfDocument(data);
* // Access the first page of the document
* let page: PdfPage = document.getPage(0);
* // Create a text element
* let element: PdfTextElement = {
* text: 'Hello world drawn inside rectangle bounds.',
* font: document.embedFont(PdfFontFamily.helvetica, 12, PdfFontStyle.regular),
* brush: new PdfBrush({ r: 0, g: 0, b: 0 })
* };
* // Define the rectangle bounds
* let rect: Rectangle = { x: 10, y: 20, width: 200, height: 50 };
* // Draw the text element inside rectangle bounds
* page.graphics.drawTextElement(element, rect);
* // Save and destroy the document
* document.save('output.pdf');
* document.destroy();
* ```
*
* @param {PdfTextElement} element The text element to draw.
* @param {Rectangle} bounds The bounds within which the text element should be drawn.
* @returns {void} Nothing.
*/
drawTextElement(element: PdfTextElement, bounds: Rectangle): void;
/**
* Pops and restores a graphics state from the stack and emits the 'Q' operator.
*
* @private
* @returns {PdfGraphicsState} The restored graphics state.
*/
_doRestore(): PdfGraphicsState;
private _beginMarkContent;
private _endMarkContent;
/**
* Resolves and writes all pending resources images, fonts, templates, streams
* into the cross-reference table and updates resource dictionaries.
*
* @private
* @param {_PdfCrossReference} crossReference The target cross-reference table.
* @returns {void}
*/
_processResources(crossReference: _PdfCrossReference): void;
/**
* Registers an image and optional soft mask into the resource dictionary and
* caches the streams in the cross-reference.
*
* @private
* @param {PdfImage} image The image to register.
* @param {_PdfName} keyName The resource name to use under `XObject`.
* @param {_PdfDictionary} source The `XObject` dictionary to update.
* @param {_PdfCrossReference} crossReference The cross-reference to populate.
* @returns {void}
*/
_updateImageResource(image: PdfImage, keyName: _PdfName, source: _PdfDictionary, crossReference: _PdfCrossReference): void;
/**
* Registers a font resource standard or TrueType and ensures its dictionary is
* cached and referenced from the page/template resources.
*
* @private
* @param {PdfFont} font The font to register.
* @param {_PdfName} keyName The resource name to use under `Font`.
* @param {_PdfDictionary} source The `Font` dictionary to update.
* @param {_PdfCrossReference} crossReference The cross-reference to populate.
* @returns {void}
*/
_updateFontResource(font: PdfFont, keyName: _PdfName, source: _PdfDictionary, crossReference: _PdfCrossReference): void;
/**
* Emits a Bezier-approximated elliptical arc path into the content stream.
*
* @private
* @param {number} x1 Left of bounding box.
* @param {number} y1 Top of bounding box.
* @param {number} x2 Right of bounding box.
* @param {number} y2 Bottom of bounding box.
* @param {number} start Start angle in degrees (clockwise from +X).
* @param {number} sweep Sweep angle in degrees (clockwise).
* @returns {void}
*/
_constructArcPath(x1: number, y1: number, x2: number, y2: number, start: number, sweep: number): void;
/**
* Emits a Bezier-approximated pie-arc path without closing to center for pie slices.
*
* @private
* @param {number} x1 Left of bounding box.
* @param {number} y1 Top of bounding box.
* @param {number} x2 Right of bounding box.
* @param {number} y2 Bottom of bounding box.
* @param {number} start Start angle in degrees (clockwise from +X).
* @param {number} sweep Sweep angle in degrees (clockwise).
* @returns {void}
*/
_constructPiePath(x1: number, y1: number, x2: number, y2: number, start: number, sweep: number): void;
/**
* Applies pen stroke properties dash, width, join, cap, miter, color to the stream.
*
* @private
* @param {PdfPen} pen The pen to apply.
* @returns {void}
*/
_writePen(pen: PdfPen): void;
/**
* Type guard that determines if the given bounds represent a rectangle.
*
* @private
* @param {Rectangle | Point} bounds A point or rectangle.
* @returns {Rectangle} True if `bounds` is a rectangle.
*/
_isRectangle(bounds: Rectangle | Point): bounds is Rectangle;
/**
* Normalizes text for non-Unicode standard fonts by removing unsupported code points
* returning a printable subset.
*
* @private
* @param {PdfFont} font The target font.
* @param {string} value The input text.
* @returns {string} The normalized text.
*/
_normalizeText(font: PdfFont, value: string): string;
/**
* Builds a vector path from points and point types, emitting move/line/bezier segments.
*
* @private
* @param {Point[]} points The path points.
* @param {PathPointType[]} types The corresponding point types.
* @returns {void}
* @throws {Error} If path formation is incorrect.
*/
_buildUpPath(points: Point[], types: PathPointType[]): void;
/**
* Reads the next Bezier control point and advances the index.
*
* @private
* @param {Point[]} points The path points.
* @param {PathPointType[]} types The point types.
* @param {number} index The current index (at a Bezier marker).
* @returns {{ index: number, point: Point }} The updated index and point.
* @throws {Error} If the current type is not `bezier`.
*/
_getBezierPoint(points: Point[], types: PathPointType[], index: number): {
index: number;
point: Point;
};
/**
* Initializes internal graphics defaults state stack, color space flag, CTM caches, etc.
*
* @private
* @returns {void}
*/
_initialize(): void;
/**
* Ensures both stroking and non-stroking color spaces are set to `DeviceRGB` once.
*
* @private
* @returns {void}
*/
_initializeCurrentColorSpace(): void;
/**
* Applies the brush non-stroking color and caches it as the current brush.
*
* @private
* @param {PdfBrush} brush The brush to apply.
* @returns {void}
*/
_brushControl(brush: PdfBrush): void;
/**
* Applies the pen stroking attributes and caches it as the current pen.
*
* @private
* @param {PdfPen} pen The pen to apply.
* @returns {void}
*/
_penControl(pen: PdfPen): void;
/**
* Registers/selects the font in resources if needed, sets size, and updates the text state.
*
* @private
* @param {PdfFont} font The font to select.
* @param {PdfStringFormat} format The text format (used for size resolution).
* @returns {void}
*/
_fontControl(font: PdfFont, format: PdfStringFormat): void;
/**
* Resolves pen/brush overloads to a structured `{pen, brush}` result and applies state.
*
* @private
* @param {PdfPen | PdfBrush} [first] Pen or brush.
* @param {PdfBrush} [second] Optional brush.
* @returns {{pen: PdfPen, brush: PdfBrush}} The resolved pen/brush.
*/
_setPenBrush(first?: PdfPen | PdfBrush, second?: PdfBrush): {
pen: PdfPen;
brush: PdfBrush;
};
/**
* Applies pen/brush/font state and initializes color spaces when needed.
*
* @private
* @param {PdfPen} [pen] Optional pen to apply.
* @param {PdfBrush} [brush] Optional brush to apply.
* @param {PdfFont} [font] Optional font to select.
* @param {PdfStringFormat} [format] Optional text format for font selection.
* @returns {void}
*/
_stateControl(pen?: PdfPen, brush?: PdfBrush, font?: PdfFont, format?: PdfStringFormat): void;
/**
* Renders a laid-out text result into the content stream with alignment, line spacing,
* clipping, italic simulation, and resource finalization.
*
* @private
* @param {_PdfStringLayoutResult} result The layout computation result.
* @param {PdfFont} font The font to use.
* @param {PdfPen} pen Optional pen for stroke text.
* @param {PdfBrush} brush Optional brush for fill text.
* @param {number[]} layoutRectangle [x, y, width, height] in user units.
* @param {PdfStringFormat} format Text format settings.
* @returns {void}
*/
_drawStringLayoutResult(result: _PdfStringLayoutResult, font: PdfFont, pen: PdfPen, brush: PdfBrush, layoutRectangle: number[], format: PdfStringFormat): void;
/**
* Returns the next page if any, or creates and returns a new page at the end.
*
* @private
* @returns {PdfPage} The next or newly created page.
*/
_getNextPage(): PdfPage;
/**
* Begins text object, applies text rendering mode, spacing, optional bold
* emulation line width, and selects brush/pen/font as needed.
*
* @private
* @param {PdfFont} font The font.
* @param {PdfPen} pen Optional pen for stroke text.
* @param {PdfBrush} brush Optional brush for fill text.
* @param {PdfStringFormat} format Text format.
* @returns {void}
*/
_applyStringSettings(font: PdfFont, pen: PdfPen, brush: PdfBrush, format: PdfStringFormat): void;
/**
* Iterates through laid-out lines, applies horizontal alignment/indents, and writes
* text runs with the appropriate encoding pipeline.
*
* @private
* @param {_PdfStringLayoutResult} result The layout result.
* @param {PdfFont} font The font in use.
* @param {PdfStringFormat} format Text format.
* @param {number[]} layoutRectangle [x, y, width, height] area for the text.
* @returns {void}
*/
_drawLayoutResult(result: _PdfStringLayoutResult, font: PdfFont, format: PdfStringFormat, layoutRectangle: number[]): void;
/**
* Encodes and writes a CJK line, applying justification spacing when required.
*
* @private
* @param {_LineInfo} lineInfo The line to render.
* @param {number[]} layoutRectangle [x, y, width, height].
* @param {PdfFont} font The CJK font.
* @param {PdfStringFormat} format Text format.
* @returns {void}
*/
_drawCjkString(lineInfo: _LineInfo, layoutRectangle: number[], font: PdfFont, format: PdfStringFormat): void;
/**
* Converts a string to a UTF 16BE byte array and escapes PDF literal string symbols.
*
* @private
* @param {string} line The input text.
* @returns {Uint8Array} The escaped byte array.
* @throws {Error} If the input is null or undefined.
*/
_getCjkString(line: string): Uint8Array;
/**
* Escapes '(', ')', '\\', and CR for safe inclusion in a PDF literal string.
*
* @private
* @param {Uint8Array} data The raw bytes.
* @returns {Uint8Array} The escaped bytes.
* @throws {Error} If `data` is null.
*/
_escapeSymbols(data: Uint8Array): Uint8Array;
/**
* Draws a Unicode line, handling BiDi/RTL, Arabic shaping, word-space justification,
* and per-word encoding when required.
*
* @private
* @param {_LineInfo} lineInfo The line info.
* @param {number} width Available width for justification.
* @param {PdfFont} font A Unicode TrueType font.
* @param {PdfStringFormat} format Text format.
* @returns {void}
*/
_drawUnicodeLine(lineInfo: _LineInfo, width: number, font: PdfFont, format: PdfStringFormat): void;
/**
* Renders tokenized Unicode runs with explicit positioning to account for
* word spacing and character spacing.
*
* @private
* @param {string[]} blocks Encoded tokens matching `words`.
* @param {string[]} words Original word tokens (visual order).
* @param {PdfTrueTypeFont} font The TrueType font.
* @param {PdfStringFormat} format Text format.
* @param {number} wordSpacing Computed justification word spacing (extra).
* @returns {void}
*/
_drawUnicodeBlocks(blocks: string[], words: string[], font: PdfTrueTypeFont, format: PdfStringFormat, wordSpacing: number): void;
/**
* Splits a Unicode line into words, converts each word via the font reader,
* and returns both the encoded tokens and original words.
*
* @private
* @param {string} line The line to split.
* @param {PdfTrueTypeFont} ttfFont The TrueType font.
* @param {string[]} words Output word array (ignored on input).
* @returns {{tokens: string[], words: string[]}} The encoded tokens and raw words.
*/
_breakUnicodeLine(line: string, ttfFont: PdfTrueTypeFont, words: string[]): {
tokens: string[];
words: string[];
};
/**
* Converts a string using the font's TrueType reader and returns a PDF-safe
* UTF-16BE literal string.
*
* @private
* @param {string} text The text to convert.
* @param {PdfTrueTypeFont} ttfFont The font used for conversion.
* @returns {string} The converted PDF string (literal).
*/
_convertToUnicode(text: string, ttfFont: PdfTrueTypeFont): string;
/**
* Computes the vertical offset needed to achieve the requested vertical alignment.
*
* @private
* @param {number} textHeight Height of laid-out text.
* @param {number} boundsHeight Height of layout rectangle.
* @param {PdfStringFormat} format Text format.
* @returns {number} The vertical shift in user units.
*/
_getTextVerticalAlignShift(textHeight: number, boundsHeight: number, format: PdfStringFormat): number;
/**
* Computes the horizontal offset needed to achieve the requested horizontal alignment.
*
* @private
* @param {number} lineWidth The width of the rendered line.
* @param {number} boundsWidth The available width.
* @param {PdfStringFormat} format Text format.
* @returns {number} The horizontal shift in user units.
*/
_getHorizontalAlignShift(lineWidth: number, boundsWidth: number, format: PdfStringFormat): number;
/**
* Resolves paragraph/first line indents for the given line respecting bounds width.
*
* @private
* @param {_LineInfo} lineInfo The line info.
* @param {PdfStringFormat} format Text format.
* @param {number} width The line width bound.
* @param {boolean} firstLine True if this is the first line of the paragraph.
* @returns {number} The indent in user units.
*/
_getLineIndent(lineInfo: _LineInfo, format: PdfStringFormat, width: number, firstLine: boolean): number;
/**
* Writes an ASCII line as a PDF literal string, escaping parentheses,
* and applying justification if required.
*
* @private
* @param {_LineInfo} lineInfo The line to draw.
* @param {number} width Available width for justification.
* @param {PdfStringFormat} format Text format.
* @param {PdfFont} font The font used to measure.
* @returns {void}
*/
_drawAsciiLine(lineInfo: _LineInfo, width: number, format: PdfStringFormat, font: PdfFont): void;
/**
* Applies word spacing justification to the current line if conditions are met.
*
* @private
* @param {_LineInfo} lineInfo The line info.
* @param {number} boundsWidth The line width bound.
* @param {PdfStringFormat} format Text format.
* @param {PdfFont} font Font for measuring spaces.
* @returns {number} The extra word spacing applied per whitespace.
*/
_justifyLine(lineInfo: _LineInfo, boundsWidth: number, format: PdfStringFormat, font: PdfFont): number;
/**
* Determines whether the current line should be justified based on alignment,
* width, whitespace presence, and line break type.
*
* @private
* @param {_LineInfo} lineInfo The line info.
* @param {number} boundsWidth The width bound.
* @param {PdfStringFormat} format Text format.
* @param {PdfFont} font Font for character counting.
* @returns {boolean} True if justification should be applied.
*/
_shouldJustify(lineInfo: _LineInfo, boundsWidth: number, format: PdfStringFormat, font: PdfFont): boolean;
/**
* Draws underline and/or strikeout lines over the rendered text according to font flags.
*
* @private
* @param {PdfBrush} brush The brush used to color the decoration lines.
* @param {_PdfStringLayoutResult} result The layout result.
* @param {PdfFont} font The font used.
* @param {number[]} layoutRectangle [x, y, width, height] text bounds.
* @param {PdfStringFormat} format Text format.
* @returns {void}
*/
_underlineStrikeoutText(brush: PdfBrush, result: _PdfStringLayoutResult, font: PdfFont, layoutRectangle: number[], format: PdfStringFormat): void;
/**
* Creates a pen for underline/strikeout based on the brush color and font size.
*
* @private
* @param {PdfBrush} brush The text fill brush.
* @param {PdfFont} font The font used .
* @returns {PdfPen} The decoration pen.
*/
_createUnderlineStrikeoutPen(brush: PdfBrush, font: PdfFont): PdfPen;
/**
* Computes the top-left anchor for the text rectangle based on alignment against (x, y).
*
* @private
* @param {number[]} textSize The measured text size as [width, height].
* @param {number} x Anchor X.
* @param {number} y Anchor Y.
* @param {PdfStringFormat} format Text format alignment / line alignment.
* @returns {number[]} The adjusted rectangle [x, y, width, height].
*/
_checkCorrectLayoutRectangle(textSize: number[], x: number, y: number, format: PdfStringFormat): number[];
/**
* Finishes the current path by stroking/filling/closing based on pen/brush and fill mode.
*
* @private
* @param {PdfPen} [pen] Optional stroke pen.
* @param {PdfBrush} [brush] Optional fill brush.
* @param {PdfFillMode} [fillMode=PdfFillMode.winding] Fill rule to use.
* @param {boolean} [needClosing=false] Whether to close the path before painting.
* @returns {void}
*/
_drawGraphicsPath(pen?: PdfPen, brush?: PdfBrush, fillMode?: PdfFillMode, needClosing?: boolean): void;
/**
* Adjusts the coordinate system for page/template rendering, translating to a
* top-left origin if needed and honoring CropBox/MediaBox combinations.
*
* @private
* @param {PdfPage} [page] Optional page context.
* @returns {void}
*/
_initializeCoordinates(page?: PdfPage): void;
/**
* Caches an existing transparency `ExtGState` entry in the internal map and
* reconstructs its composite key.
*
* @private
* @param {_PdfReference} ref The graphics state reference.
* @param {_PdfName} name The resource name.
* @returns {void}
*/
_setTransparencyData(ref: _PdfReference, name: _PdfName): void;
/**
* Applies a translation x, -y to the provided matrix and returns it.
*
* @private
* @param {number} x Translation along X.
* @param {number} y Translation along Y.
* @param {_PdfTransformationMatrix} input The matrix to mutate.
* @returns {_PdfTransformationMatrix} The mutated matrix.
*/
_getTranslateTransform(x: number, y: number, input: _PdfTransformationMatrix): _PdfTransformationMatrix;
/**
* Applies a scale to the provided matrix and returns it.
*
* @private
* @param {number} x Scale along X.
* @param {number} y Scale along Y.
* @param {_PdfTransformationMatrix} input The matrix to mutate (or create).
* @returns {_PdfTransformationMatrix} The mutated matrix.
*/
_getScaleTransform(x: number, y: number, input: _PdfTransformationMatrix): _PdfTransformationMatrix;
/**
* Clips to the specified bounds and translates the coordinate system to the
* new top left origin.
*
* @private
* @param {number[]} clipBounds [x, y, width, height] clipping rectangle.
* @returns {void}
*/
_clipTranslateMargins(clipBounds: number[]): void;
/**
* Applies a clipping rectangle and translates the graphics coordinate system
* based on the specified margin and template bounds.
*
* @private
* @param {number[]} clipBounds The bounds used to compute clipping and translation,
* specified as an array containing margin and template offsets.
* @returns {void} Nothing.
*/
_clipTranslateMarginsWithBounds(clipBounds: number[]): void;
/**
* Applies a skew to the current CTM by composing a skew matrix into the stream
* and accumulating it into the local CTM.
*
* @private
* @param {number} angleX Skew angle along X (degrees).
* @param {number} angleY Skew angle along Y (degrees).
* @returns {void}
*/
_skewTransform(angleX: number, angleY: number): void;
/**
* Skews the provided matrix by -angleX, -angleY and returns it.
*
* @private
* @param {number} angleX Skew angle X in degrees.
* @param {number} angleY Skew angle Y in degrees.
* @param {_PdfTransformationMatrix} input The matrix to mutate.
* @returns {_PdfTransformationMatrix} The mutated matrix.
*/
_getSkewTransform(angleX: number, angleY: number, input: _PdfTransformationMatrix): _PdfTransformationMatrix;
}
/**
* Represents an internal affine transformation matrix used for PDF graphics
* operations such as translate, scale, rotate, skew, and matrix multiplication.
*
* @private
*/
export declare class _PdfTransformationMatrix {
/**
* Internal 2D matrix elements.
*
* @private
*/
_matrix: _Matrix;
/**
* Initializes a new identity transformation matrix (1 0 0 1 0 0).
*
* @private
*/
constructor();
/**
* Applies a translation to the matrix.
*
* @param {number} x Horizontal translation.
* @param {number} y Vertical translation.
* @returns {void} nothing.
*
* @private
*/
_translate(x: number, y: number): void;
/**
* Replaces the scale components of the transformation matrix.
*
* @param {number} x Scale value along X.
* @param {number} y Scale value along Y.
* @returns {void} nothing.
*
* @private
*/
_scale(x: number, y: number): void;
/**
* Rotates the matrix by the specified angle in degrees.
*
* @param {number} angle Rotation angle in degrees.
* @returns {void} nothing.
*
* @private
*/
_rotate(angle: number): void;
/**
* Multiplies this transformation matrix with another transformation matrix.
*
* @param {_PdfTransformationMatrix} matrix The matrix to multiply with.
* @returns {void} nothing.
*
* @private
*/
_multiply(matrix: _PdfTransformationMatrix): void;
/**
* Converts the matrix into a space-separated string representation suitable
* for writing into a PDF content stream.
*
* @returns {string} String representation of the matrix.
*
* @private
*/
_toString(): string;
/**
* Applies a skew transform using tangent based shear operations.
*
* @param {number} angleX Skew angle along X axis in degrees.
* @param {number} angleY Skew angle along Y axis in degrees.
* @returns {void} nothing.
*
* @private
*/
_skew(angleX: number, angleY: number): void;
/**
* Converts degrees to radians.
*
* @param {number} degreesX Angle in degrees.
* @returns {number} Equivalent angle in radians.
*
* @private
*/
_degreeToRadians(degreesX: number): number;
}
/**
* Internal low level 2D affine matrix representing the six element PDF transformation matrix.
*
* @private
*/
export declare class _Matrix {
/**
* Six-element array [a, b, c, d, tx, ty] representing the affine transform.
*
* @private
*/
_elements: number[];
/**
* Initializes a new instance of the matrix.
*
* @private
*/
constructor();
constructor(elements: number[]);
constructor(m11: number, m12: number, m21: number, m22: number, dx: number, dy: number);
/**
* Gets the translation dx component of the matrix.
*
* @returns {number} The X offset.
*
* @private
*/
readonly _offsetX: number;
/**
* Gets the translation dy component of the matrix.
*
* @returns {number} The Y offset.
*
* @private
*/
readonly _offsetY: number;
/**
* Creates a deep copy of the matrix.
*
* @returns {_Matrix} A new matrix with identical values.
*
* @private
*/
_clone(): _Matrix;
/**
* Overrides the translation components of the matrix.
*
* @param {number} x X translation.
* @param {number} y Y translation.
* @returns {void} nothing.
*
* @private
*/
_translate(x: number, y: number): void;
/**
* Transforms a point using this matrix.
*
* @param {Point} points The point to transform.
* @returns {Point} The transformed point.
*
* @private
*/
_transform(points: Point): Point;
/**
* Multiplies this matrix with another matrix using affine matrix multiplication rules.
*
* @param {_Matrix} matrix The matrix to multiply with.
* @returns {void} nothing.
*
* @private
*/
_multiply(matrix: _Matrix): void;
}
/**
* Represents a state of the graphics from a PDF page.
*
* ```typescript
* // 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 state
* let state: PdfGraphicsState = graphics.save();
* // Set graphics translate transform
* graphics.translateTransform({x: 100, y: 100});
* // Draw 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 state
* graphics.restore(state);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfGraphicsState {
/**
* Owning graphics context for this saved state.
*
* @private
*/
_g: PdfGraphics;
/**
* Transformation matrix captured with this state.
*
* @private
*/
_transformationMatrix: _PdfTransformationMatrix;
/**
* Text rendering mode at save time.
*
* @private
*/
_textRenderingMode: _TextRenderingMode;
/**
* Character spacing saved in the state.
*
* @private
*/
_charSpacing: number;
/**
* Word spacing saved in the state.
*
* @private
*/
_wordSpacing: number;
/**
* Text horizontal scaling saved in the state.
*
* @private
*/
_textScaling: number;
/**
* Currently active pen when the state was saved.
*
* @private
*/
_currentPen: PdfPen;
/**
* Currently active brush when the state was saved.
*
* @private
*/
_currentBrush: PdfBrush;
/**
* Currently active font when the state was saved.
*
* @private
*/
_currentFont: any;
/**
* Initializes a new instance of the `PdfGraphicsState` class.
*
* @private
* @param {PdfGraphics} graphics Graphics.
* @param {_PdfTransformationMatrix} matrix Matrix.
*
*/
constructor(graphics: PdfGraphics, matrix: _PdfTransformationMatrix);
}
/**
* Internal container for an ExtGState transparency object, including its
* dictionary, name, reference, and unique cache key.
*
* @private
*/
declare class _TransparencyData {
/**
* Unique cache key for the transparency entry.
*
* @private
*/
_key: string;
/**
* Cross-reference to the stored ExtGState dictionary.
*
* @private
*/
_reference: _PdfReference;
/**
* The ExtGState dictionary describing transparency parameters.
*
* @private
*/
_dictionary: _PdfDictionary;
/**
* Local resource name assigned to this transparency dictionary.
*
* @private
*/
_name: _PdfName;
}
export declare enum _TextRenderingMode {
fill = 0,
stroke = 1,
fillStroke = 2,
none = 3,
clipFlag = 4,
clipFill = 4,
clipStroke = 5,
clipFillStroke = 6,
clip = 7
}
/**
* Represents a brush for the PDF page.
*
* ```typescript
* // 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 brush
* let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
* // Draw a rectangle using brush
* graphics.drawRectangle({x: 10, y: 10, width: 100, height: 100}, brush);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfBrush {
/**
* Brush color used for fill operations.
*
* @private
*/
_color: PdfColor;
/**
* Initializes a new instance of the `PdfBrush` class.
*
* ```typescript
* // 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 brush
* let brush: PdfBrush = new PdfBrush();
* // Draw a rectangle using brush
* graphics.drawRectangle({x: 10, y: 10, width: 100, height: 100}, brush);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor();
/**
* Initializes a new instance of the `PdfBrush` class.
*
* @param {PdfColor} color Color.
*
* ```typescript
* // 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 brush
* let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
* // Draw a rectangle using brush
* graphics.drawRectangle({x: 10, y: 10, width: 100, height: 100}, brush);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(color: PdfColor);
}
/**
* Represents a pen for the PDF page.
*
* ```typescript
* // 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 using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
export declare class PdfPen {
/**
* Pen color used for stroking operations.
*
* @private
*/
_color: PdfColor;
/**
* Pen width in points.
*
* @private
*/
_width: number;
/**
* Dash offset for dash patterns.
*
* @private
*/
_dashOffset: number;
/**
* Dash pattern array defining dashes and gaps.
*
* @private
*/
_dashPattern: number[];
/**
* Enumerated dash style used by the pen.
*
* @private
*/
_dashStyle: PdfDashStyle;
/**
* Line cap style used when stroking paths.
*
* @private
*/
_lineCap: PdfLineCap;
/**
* Line join style used when stroking path joins.
*
* @private
*/
_lineJoin: PdfLineJoin;
/**
* Miter limit applied when `miter` joins are used.
*
* @private
*/
_miterLimit: number;
/**
* Initializes a new instance of the `PdfPen` class.
*
* @param {PdfColor} color Color.
* @param {number} width Width.
*
* ```typescript
* // 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 using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(color: PdfColor, width: number);
/**
* Initializes a new instance of the `PdfPen` class with customization properties.
*
* @remarks
* The `PdfPen` class is used to draw lines, curves, and outlines of shapes in a PDF document.
* This constructor allows you to specify the color and width, along with optional properties
* for advanced line styling such as dash patterns, line caps, and joins.
*
* @param {PdfColor} color - The color of the pen used for drawing.
* @param {number} width - The width of the pen in points (1 point = 1/72 inch).
* @param {object} [properties] - Optional customization properties for advanced pen styling.
* @param {number} [properties.dashOffset] - The offset distance from the start of a line
* where the dash pattern begins. Measured in points.
* @param {number[]} [properties.dashPattern] - An array defining the dash pattern as
* alternating lengths of dashes and gaps.
* @param {PdfDashStyle} [properties.dashStyle] - The predefined dash style of the pen.
* @param {number} [properties.miterLimit] - The limit of the miter length to the line width ratio.
* Used when lineJoin is set to Miter. Default is typically 10.
* @param {PdfLineCap} [properties.lineCap] - The style applied to the ends of lines.
* @param {PdfLineJoin} [properties.lineJoin] - The style applied to the corners where two lines meet.
*
* @example
* ```typescript
* // 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}, 4, {dashOffset: 0.5, dashPattern: [4, 2, 1, 3], dashStyle: PdfDashStyle.custom, miterLimit: 2, lineCap: PdfLineCap.round, lineJoin: PdfLineJoin.bevel});
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
constructor(color: PdfColor, width: number, properties: {
dashOffset?: number;
dashPattern?: number[];
dashStyle?: PdfDashStyle;
miterLimit?: number;
lineCap?: PdfLineCap;
lineJoin?: PdfLineJoin;
});
/**
* Gets the pen color used for drawing.
*
* @returns {PdfColor} The current pen color.
* ```typescript
* // 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}, 4, {dashOffset: 0.5, dashPattern: [4,2,1,3], dashStyle: PdfDashStyle.custom, miterLimit:2, lineCap: PdfLineCap.round, lineJoin: PdfLineJoin.bevel});
* // Gets the pen color used for drawing
* const color: PdfColor = pen.color;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the pen color used for drawing.
*
* @param {PdfColor} value - The color to use for the pen.
* ```typescript
* // 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}, 4);
* // Set the pen color for drawing
* pen.color = {r: 255, g: 0, b: 0};
* // Draw using the pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
color: PdfColor;
/**
* Gets the width of the pen.
*
* @returns {number} The pen width in points.
* ```typescript
* // 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}, 4, {dashOffset: 0.5, dashPattern: [4,2,1,3], dashStyle: PdfDashStyle.custom, miterLimit:2, lineCap: PdfLineCap.round, lineJoin: PdfLineJoin.bevel});
* // Gets the width of the pen used for drawing
* const w: number = pen.width;
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the width of the pen.
*
* @param {number} value - The pen width in points.
* ```typescript
* // 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);
* // Sets the pen width for drawing
* pen.width = 2;
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
width: number;
/**
* Gets the dash phase offset that shifts where the dash pattern begins. Measured in points.
*
* @returns {number} The dash offset in points.
* ```typescript
* // 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}, 4, {dashOffset: 0.5, dashPattern: [4,2,1,3], dashStyle: PdfDashStyle.custom, miterLimit:2, lineCap: PdfLineCap.round, lineJoin: PdfLineJoin.bevel});
* const offset = pen.dashOffset;
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the dash phase offset that determines where the dash pattern begins. Measured in points.
*
* @param {number} value - The dash offset in points.
* ```typescript
* // 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}, 4);
* //Sets the dashOffset value for drawing
* pen.dashOffset = 0.5;
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
dashOffset: number;
/**
* Gets the dash pattern array specifying alternating dash and gap lengths in points.
*
* @returns {number[]} The dash/gap lengths array.
* ```typescript
* // 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}, 4, {dashOffset: 0.5, dashPattern: [4,2,1,3], dashStyle: PdfDashStyle.custom});
* // Gets the dash pattern used for drawing
* const pattern: number[] = pen.dashPattern;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the dash pattern array specifying alternating dash and gap lengths in points.
*
* @remarks
* The dash pattern cannot be set when the pen's `dashStyle` is `PdfDashStyle.Solid`.
*
* @param {number[]} value - Array of numbers representing dash and gap lengths.
* ```typescript
* // Create a new PDF document
* let document: PdfDocument = new PdfDocument();
* // Add a new page
* let page: PdfPage = document.pages.add();
* // Gets the graphics of the PDF page
* let graphics: PdfGraphics = page.graphics;
* // Create a pen with width 2
* let pen: PdfPen = new PdfPen({r:0, g:0, b:0}, 2);
* //Sets the dashPattern value for drawing
* pen.dashPattern = [3, 1, 3, 1];
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
dashPattern: number[];
/**
* Gets the dash style of the pen.
*
* @returns {PdfDashStyle} The dash style.
* ```typescript
* // 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}, 4, {dashOffset: 0.5, dashPattern: [4,2,1,3], dashStyle: PdfDashStyle.custom, miterLimit:2, lineCap: PdfLineCap.round, lineJoin: PdfLineJoin.bevel});
* // Gets pen dash style used for drawing
* const style: PdfDashStyle = pen.dashStyle;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the dash style of the pen.
*
* @param {PdfDashStyle} value - The dash style to apply.
* ```typescript
* // Create a new PDF document
* let document: PdfDocument = new PdfDocument();
* // Add a new page
* let page: PdfPage = document.pages.add();
* // Gets the graphics of the PDF page
* let graphics: PdfGraphics = page.graphics;
* // Create a pen and set a dash style
* let pen: PdfPen = new PdfPen({r:0, g:0, b:0}, 2);
* // Sets the dashStyle value for drawing
* pen.dashStyle = PdfDashStyle.custom;
* // Sets the dash pattern for custom style
* pen.dashPattern = [4, 2, 1, 3];
* //Sets the dashStyle value for drawing
* // For custom style, set the pattern as well
* pen.dashStyle = PdfDashStyle.custom;
* pen.dashPattern = [4,2,1,3];
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
dashStyle: PdfDashStyle;
/**
* Gets the miter limit value, used when lineJoin is Miter.
*
* @returns {number} The miter limit value.
* ```typescript
* // 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}, 4);
* // Gets miter limit used for drawing
* const m: number = pen.miterLimit;
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the miter limit for mitered line joins.
*
* @param {number} value - The miter limit value.
* ```typescript
* // Create a new PDF document
* let document: PdfDocument = new PdfDocument();
* // Add a new page
* let page: PdfPage = document.pages.add();
* // Gets the graphics of the PDF page
* let graphics: PdfGraphics = page.graphics;
* // Create a pen and set miter limit
* let pen: PdfPen = new PdfPen({r:0, g:0, b:0}, 2);
* // Sets the line join type as miter.
* pen.lineJoin = PdfLineJoin.miter;
* // Sets the miter limit value for drawing
* pen.miterLimit = 4;
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
miterLimit: number;
/**
* Gets the line cap style applied to the ends of lines.
*
* @returns {PdfLineCap} The line cap style.
* ```typescript
* // 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}, 4);
* // Gets line cap style used for drawing
* const cap: PdfLineCap = pen.lineCap; // PdfLineCap.flat | round | square
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the line cap style applied to the ends of lines.
*
* @param {PdfLineCap} value - The line cap style.
* ```typescript
* // Create a new PDF document
* let document: PdfDocument = new PdfDocument();
* // Add a new page
* let page: PdfPage = document.pages.add();
* // Gets the graphics of the PDF page
* let graphics: PdfGraphics = page.graphics;
* // Create a pen and set line cap
* let pen: PdfPen = new PdfPen({r:0, g:0, b:0}, 2);
* // Sets the line cap value used for drawing
* pen.lineCap = PdfLineCap.round;
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
lineCap: PdfLineCap;
/**
* Gets the line join style used at intersections between line segments.
*
* @returns {PdfLineJoin} The line join style.
* ```typescript
* // 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}, 4);
* // Gets the line join style used for drawing
* const join: PdfLineJoin = pen.lineJoin; // PdfLineJoin.miter | round | bevel
* // Destroy the document
* document.destroy();
* ```
*/
/**
* Sets the line join style used at intersections between line segments.
*
* @param {PdfLineJoin} value - The line join style to set.
* ```typescript
* // Create a new PDF document
* let document: PdfDocument = new PdfDocument();
* // Add a new page
* let page: PdfPage = document.pages.add();
* // Gets the graphics of the PDF page
* let graphics: PdfGraphics = page.graphics;
* // Create a pen and set line join
* let pen: PdfPen = new PdfPen({r:0, g:0, b:0}, 2);
* // Sets the line join type for drawing
* pen.lineJoin = PdfLineJoin.bevel;
* // Draw a rectangle using pen
* graphics.drawRectangle({x: 150, y: 50, width: 50, height: 50}, pen);
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
lineJoin: PdfLineJoin;
}
/**
* Provides internal unit conversion between various measurement units used
* in PDF graphics pixels, points, inches, centimeters, etc.
*
* @private
*/
export declare class _PdfUnitConvertor {
/**
* Horizontal pixel resolution used for unit conversions.
*
* @private
*/
_horizontalResolution: number;
/**
* Cached proportion constants for unit conversion.
*
* @private
*/
_proportions: number[];
/**
* Initializes a new unit converter using the default horizontal resolution.
*
* @private
*/
constructor();
/**
* Computes and returns the proportional conversion values based on the
* specified pixel resolution.
*
* @param {number} pixel The horizontal pixel resolution.
* @returns {number[]} The array of proportional constants.
*
* @private
*/
_updateProportions(pixel: number): number[];
/**
* Converts a value from one unit type to another.
*
* @param {number} value The value to convert.
* @param {_PdfGraphicsUnit} from The source unit.
* @param {_PdfGraphicsUnit} to The destination unit.
* @returns {number} The converted value.
*
* @private
*/
_convertUnits(value: number, from: _PdfGraphicsUnit, to: _PdfGraphicsUnit): number;
/**
* Converts a pixel value into the specified target unit.
*
* @param {number} value Pixel value.
* @param {_PdfGraphicsUnit} to Target unit.
* @returns {number} Converted value.
*
* @private
*/
_convertFromPixels(value: number, to: _PdfGraphicsUnit): number;
/**
* Converts a value from the specified unit into pixels.
*
* @param {number} value The value to convert.
* @param {_PdfGraphicsUnit} from The source unit.
* @returns {number} Converted pixel value.
*
* @private
*/
_convertToPixels(value: number, from: _PdfGraphicsUnit): number;
}
export {};