Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- nestjs
- 게임
- Bull
- Python
- react
- mongoose
- Dinosaur
- OCR
- typeORM
- class
- jest
- JavaScript
- Nest.js
- dfs
- Express
- 정렬
- nodejs
- MySQL
- TypeScript
- 공룡게임
- Sequelize
- MongoDB
- GIT
- AWS
- flask
- Queue
- 자료구조
- cookie
- game
Archives
- Today
- Total
포시코딩
바코드 이미지 생성과 svg 메일 전송 본문
728x90
https://yoksel.github.io/url-encoder/
URL-encoder for SVG
yoksel.github.io
npm i jsbarcode xmldom
npm i -D @types/xmldom
import { DOMImplementation, XMLSerializer } from 'xmldom';
import JsBarcode from 'jsbarcode';
// ... 생략
private createBarcodeImage(code: string) {
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',
);
const symbols = /[\r\n%#()<>?[\\\]^`{|}]/g;
JsBarcode(svgNode, code, {
xmlDocument: document,
});
let svgText = xmlSerializer.serializeToString(svgNode);
svgText = svgText.replace(/"/g, `'`);
svgText = svgText.replace(/>\s{1,}</g, `><`);
svgText = svgText.replace(/\s{2,}/g, ` `);
svgText = svgText.replace(symbols, encodeURIComponent);
return `data:image/svg+xml,${svgText}`;
}
728x90