🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@olptools/pdf-utils

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@olptools/pdf-utils - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+1
test/example.html
<b>Hello {{name}}!</b>
const { readFileSync, writeFileSync } = require('fs');
const { join } = require('path');
const { HTMLParser } = require('..');
const parser = new HTMLParser(readFileSync(join(__dirname, "./example.html"), "utf-8"));
parser.pdf({ name: "CamiloTD" }).then(pdf => {
console.log({ pdf })
writeFileSync(join(__dirname, "example.pdf"), pdf);
}).catch(console.log);
+7
-1

@@ -1,1 +0,7 @@

export {};
export declare class HTMLParser {
_html: string;
constructor(_html: string);
html(data: any): string;
pdf(data: any): Promise<any>;
}
export default HTMLParser;
+8
-15

@@ -5,4 +5,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {

Object.defineProperty(exports, "__esModule", { value: true });
exports.HTMLParser = void 0;
const handlebars_1 = __importDefault(require("handlebars"));
const wkhtmltopdf_1 = __importDefault(require("wkhtmltopdf"));
const html_pdf_node_1 = __importDefault(require("html-pdf-node"));
class HTMLParser {

@@ -15,18 +16,10 @@ constructor(_html) {

}
pdf(data) {
return new Promise(async (done, err) => {
const stream = (0, wkhtmltopdf_1.default)(await this.html(data));
const chunks = [];
stream
.on('data', d => {
chunks.push(d);
})
.on('end', async function () {
const buf = Buffer.concat(chunks);
return done(buf);
})
.on('error', err);
});
async pdf(data) {
return await html_pdf_node_1.default.generatePdf({
content: await this.html(data)
}, { format: 'A4' });
}
}
exports.HTMLParser = HTMLParser;
exports.default = HTMLParser;
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;AAAA,4DAAoC;AACpC,8DAAoC;AAEpC,MAAM,UAAU;IAEZ,YAAoB,KAAa;Q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IAAI,EAAE,CAAC,CAAC;IACzB,CAAC;CACJ;AAbD,gCAaC;AAED,kBAAe,UAAU,CAAC"}
import Handlebars from "handlebars";
import HTMLToPDF from "wkhtmltopdf";
import HTMLToPDF from "html-pdf-node";
class HTMLParser {
export class HTMLParser {

@@ -12,17 +12,9 @@ constructor (public _html: string) {}

pdf (data: any) {
return new Promise(async (done, err) => {
const stream = HTMLToPDF(await this.html(data));
const chunks = [];
stream
.on('data', d => {
chunks.push(d)
})
.on('end', async function () {
const buf = Buffer.concat(chunks);
return done(buf);
})
.on('error', err);
});
async pdf (data: any) {
return await HTMLToPDF.generatePdf({
content: await this.html(data)
}, { format: 'A4' });
}
}
}
export default HTMLParser;
{
"name": "@olptools/pdf-utils",
"version": "1.0.0",
"main": "index.js",
"version": "1.0.1",
"main": "build/index.js",
"license": "MIT",
"dependencies": {
"handlebars": "^4.7.7",
"wkhtmltopdf": "^0.4.0"
"html-pdf-node": "^1.0.8"
},

@@ -15,4 +15,5 @@ "devDependencies": {

"scripts": {
"build": "tsc"
"build": "tsc",
"test": "node test/index.test.js"
}
}