APIs

Show:

Static canvas class

Item Index

Methods

Methods

(
  • [options]
  • [reviver]
)
String

Returns SVG representation of canvas

Parameters:

  • [options] Object optional

    Options object for SVG output

    • [suppressPreamble=false] Boolean optional

      If true xml tag is not included

    • [viewBox] Object optional

      SVG viewbox object

      • [x] Number optional
        x-cooridnate of viewbox
      • [y] Number optional
        y-coordinate of viewbox
      • [width] Number optional
        Width of viewbox
      • [height] Number optional
        Height of viewbox
    • [encoding=UTF-8] String optional

      Encoding of SVG output

  • [reviver] Function optional

    Method for further parsing of svg elements, called after each fabric object converted into svg representation.

Returns:

String:

SVG string

Example:

Normal SVG output var svg = canvas.toSVG();

SVG output without preamble (without <?xml ../>) var svg = canvas.toSVG({suppressPreamble: true});

SVG output with viewBox attribute var svg = canvas.toSVG({ viewBox: { x: 100, y: 100, width: 200, height: 300 } });

SVG output with different encoding (default: UTF-8) var svg = canvas.toSVG({encoding: 'ISO-8859-1'});

Modify SVG output with reviver function var svg = canvas.toSVG(null, function(svg) { return svg.replace('stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; ', ''); });

(
  • [propertiesToInclude]
)
String

Returns JSON representation of canvas

Parameters:

  • [propertiesToInclude] Array optional

    Any properties that you might want to additionally include in the output

Returns:

String:

JSON string

Example:

JSON without additional properties var json = canvas.toJSON();

JSON with additional properties included var json = canvas.toJSON(['lockMovementX', 'lockMovementY', 'lockRotation', 'lockScalingX', 'lockScalingY', 'lockUniScaling']);

JSON without default values canvas.includeDefaultValues = false; var json = canvas.toJSON();