代码如下:
1 var { DOMImplementation, XMLSerializer } = require(‘xmldom‘); 2 var xmlSerializer = new XMLSerializer(); 3 //http://www.w3.org/1999/xhtml 4 var document = new DOMImplementation().createDocument(‘html‘, ‘html‘, null); 5 //http://www.w3.org/2000/svg 6 var svgNode = document.createElementNS(‘svg‘, ‘svg‘); 7 var JsBarcode = require(‘jsbarcode‘); 8 var svg2png = require(‘svg2png‘); 9 var fs = require(‘fs‘) 10 11 JsBarcode(svgNode, ‘test‘, { 12 xmlDocument: document, 13 }); 14 15 var svgText = xmlSerializer.serializeToString(svgNode); 16 var png = svg2png.sync(svgText); 17 fs.writeFileSync(‘条形码.png‘, png); 18 console.log(‘条形码生成完毕‘);
原文地址:https://www.cnblogs.com/mxh-java/p/12076508.html
时间: 2024-10-08 01:06:10