-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(classes/generator.js): html-pdf installed as default
- Loading branch information
Showing
1 changed file
with
2 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
@@ -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`), | ||
|
@@ -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]'); | ||
} | ||
} | ||
} |