parent
27d1d69360
commit
a35f8cfd3a
@ -1,4 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import bwipjs from "bwip-js";
|
||||
import cheerio from "cheerio";
|
||||
import fs from "fs";
|
||||
import Handlebars from 'handlebars';
|
||||
@ -82,6 +83,11 @@ export class PdfCreator {
|
||||
return i18next.t(str, PdfCreator.interpolations).toString();
|
||||
}
|
||||
);
|
||||
await Handlebars.registerHelper('--bc',
|
||||
function (str) {
|
||||
return "data:image";
|
||||
}
|
||||
);
|
||||
this.browser = await puppeteer.launch({ headless: true, args: minimal_args });
|
||||
}
|
||||
|
||||
@ -121,6 +127,9 @@ export class PdfCreator {
|
||||
const $ = cheerio.load(html)
|
||||
$('img').each(async (index, element) => {
|
||||
let imgsrc = $(element).attr("src");
|
||||
if (imgsrc.startsWith("data:image")) {
|
||||
return;
|
||||
}
|
||||
const img_type = mime.lookup(imgsrc);
|
||||
|
||||
if (!(img_type.includes("image"))) {
|
||||
@ -186,7 +195,7 @@ export class PdfCreator {
|
||||
* @param content Barcode content/text - please remember that some formats only support certain input types.
|
||||
* @returns Barcode image as base64 encoded png string.
|
||||
*/
|
||||
public async generateBarcode(type: string, content: string): Promise<String> {
|
||||
public static async generateBarcode(type: string, content: string): Promise<String> {
|
||||
let barcode: Buffer = await bwipjs.toBuffer({
|
||||
bcid: type,
|
||||
text: content,
|
||||
|
Loading…
x
Reference in New Issue
Block a user