Skip to content

Commit

Permalink
feat(classes/generator.js): html-pdf installed as default
Browse files Browse the repository at this point in the history
  • Loading branch information
rimiti committed May 27, 2020
1 parent 3836a5c commit 7a50519
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/classes/generator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import moment from 'moment';
import pug from 'pug';
import fs from 'fs';
import path from 'path';
import htmlPDF from 'html-pdf';
import Common from './common';
import Recipient from './recipient';
import Emitter from './emitter';
Expand Down Expand Up @@ -462,8 +462,7 @@ export default class Generator extends Common {
* @private
*/
_toPDF(keys, params = []) {
const htmlToPdf = this._loadHtmlToPdf();
const pdf = htmlToPdf.create(this._toHTML(keys, params).html, {timeout: '90000'});
const pdf = htmlPDF.create(this._toHTML(keys, params).html, {timeout: '90000'});
return {
pdf,
toFile: (filepath) => this._toFileFromPDF(pdf, (filepath) || `${keys.filename}.pdf`),
Expand Down Expand Up @@ -573,18 +572,4 @@ export default class Generator extends Common {
this._availableLocale = (config && config.locales) ? config.locales : ['en', 'fr'];
if (config) i18n.configure(config);
}

/**
* @description Loads html-pdf module if available
* @returns {*}
* @private
*/
_loadHtmlToPdf() {
try {
/* eslint import/no-unresolved: [2, { ignore: ['html-pdf'] }] */
return require('html-pdf'); // eslint-disable-line global-require
} catch (err) {
throw new Error('Cannot load html-pdf. Try installing it: npm i -S [email protected]');
}
}
}

0 comments on commit 7a50519

Please sign in to comment.