Skip to main content

Class: Canvg

SVG renderer on canvas.

Methods

from

Static from(ctx, svg, options?): Promise<Canvg>

Create Canvg instance from SVG source string or URL.

Parameters

NameTypeDescription
ctxRenderingContext2DRendering context.
svgstringSVG source string or URL.
optionsIOptionsRendering options.

Returns

Promise<Canvg>

Canvg instance.

Defined in

src/Canvg.ts:32


fromString

Static fromString(ctx, svg, options?): Canvg

Create Canvg instance from SVG source string.

Parameters

NameTypeDescription
ctxRenderingContext2DRendering context.
svgstringSVG source string.
optionsIOptionsRendering options.

Returns

Canvg

Canvg instance.

Defined in

src/Canvg.ts:50


fork

fork(ctx, svg, options?): Promise<Canvg>

Create new Canvg instance with inherited options.

Parameters

NameTypeDescription
ctxRenderingContext2DRendering context.
svgstringSVG source string or URL.
optionsIOptionsRendering options.

Returns

Promise<Canvg>

Canvg instance.

Defined in

src/Canvg.ts:105


forkString

forkString(ctx, svg, options?): Canvg

Create new Canvg instance with inherited options.

Parameters

NameTypeDescription
ctxRenderingContext2DRendering context.
svgstringSVG source string.
optionsIOptionsRendering options.

Returns

Canvg

Canvg instance.

Defined in

src/Canvg.ts:123


ready

ready(): Promise<void>

Document is ready promise.

Returns

Promise<void>

Ready promise.

Defined in

src/Canvg.ts:138


isReady

isReady(): boolean

Document is ready value.

Returns

boolean

Is ready or not.

Defined in

src/Canvg.ts:146


render

render(options?): Promise<void>

Render only first frame, ignoring animations and mouse.

Parameters

NameTypeDescription
optionsIScreenStartOptionsRendering options.

Returns

Promise<void>

Defined in

src/Canvg.ts:154


start

start(options?): void

Start rendering.

Parameters

NameTypeDescription
optionsIScreenStartOptionsRender options.

Returns

void

Defined in

src/Canvg.ts:171


stop

stop(): void

Stop rendering.

Returns

void

Defined in

src/Canvg.ts:188


resize

resize(width, height?, preserveAspectRatio?): void

Resize SVG to fit in given size.

Parameters

NameTypeDefault value
widthnumberundefined
heightnumberwidth
preserveAspectRatiostring | booleanfalse

Returns

void

Defined in

src/Canvg.ts:198

Properties

parser

Readonly parser: Parser

XML/HTML parser instance.

Defined in

src/Canvg.ts:64


screen

Readonly screen: Screen

Screen instance.

Defined in

src/Canvg.ts:68


document

Readonly document: Document

Canvg Document.

Defined in

src/Canvg.ts:72


documentElement

Private Readonly documentElement: SVGElement

Defined in

src/Canvg.ts:73


options

Private Readonly options: IOptions

Defined in

src/Canvg.ts:74

Constructors

constructor

new Canvg(ctx, svg, options?)

Main constructor.

Parameters

NameTypeDescription
ctxRenderingContext2DRendering context.
svgDocumentSVG Document.
optionsIOptionsRendering options.

Defined in

src/Canvg.ts:82