Skip to main content

Class: Canvg

SVG renderer on canvas.

Constructors​

constructor​

• new Canvg(ctx, svg, options?)

Main constructor.

Parameters​

NameTypeDescription
ctxRenderingContext2DRendering context.
svgDocumentSVG Document.
optionsIOptionsRendering options.

Defined in​

src/Canvg.ts:82

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

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