Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jiandan217 opened this issue Mar 8, 2023 · 0 comments

Comments

@jiandan217
Copy link

jiandan217 commented Mar 8, 2023

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
[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant