Skip to content

README With svg demo: TypeError: document.createElement(...).getContext is not a function #428

@jiandan217

Description

@jiandan217

I want to use JsBarcode in svg, so i found this in readme file.
i try this step by step, but got some errors

const { DOMImplementation, XMLSerializer } = require('xmldom');
const xmlSerializer = new XMLSerializer();
const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);
const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');

JsBarcode(svgNode, 'test', {
    xmlDocument: document,
});

error:

Thrown:
TypeError: document.createElement(...).getContext is not a function
    at messureText (/Users/longen/temp/node_modules/jsbarcode/bin/renderers/shared.js:77:42)
    at calculateEncodingAttributes (/Users/longen/temp/node_modules/jsbarcode/bin/renderers/shared.js:39:16)
    at SVGRenderer.prepareSVG (/Users/longen/temp/node_modules/jsbarcode/bin/renderers/svg.js:59:44)
    at SVGRenderer.render (/Users/longen/temp/node_modules/jsbarcode/bin/renderers/svg.js:36:9)
    at render (/Users/longen/temp/node_modules/jsbarcode/bin/JsBarcode.js:227:11)
    at API.render (/Users/longen/temp/node_modules/jsbarcode/bin/JsBarcode.js:206:3)
    at JsBarcode (/Users/longen/temp/node_modules/jsbarcode/bin/JsBarcode.js:76:55)

env:
node: v10.24.1
jsbarcode@3.11.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions