Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// pdf.create(html, {
// format: 'A4'
// }).toFile('./profile.pdf', (err, result) => {
// if (err) {
// return console.error(err)
// }
// console.log(result)
// })
const htmlPdf = require('html-pdf-chrome')
const options = {
// port: 9222, // port Chrome is listening on
};
htmlPdf.create(html, options).then(pdf => pdf.toFile('./profile.pdf'))
function p () {
setTimeout(() => {
console.log('settimeout 0')
}, 0)
window.requestAnimationFrame(() => {
console.log('request')
})
setTimeout(() => {
console.log('settimeout 0')
}, 0)
setTimeout(() => {
console.log('settimeout 17')
}, 17)
}
return function createPdf (url, job) {
debug('Creating PDF for url %s with options %s', url, JSON.stringify(options))
var generationId = uuid()
var generated_at = utils.getCurrentDateTimeAsString()
var jobId = job.id
function createResponseObject() {
return {
id: generationId,
generated_at: generated_at
}
}
return htmlPdf
.create(url, options)
.then((pdf) => {
var pdfPath = path.join(storagePath, 'pdf', (uuid() + '.pdf'))
debug('Saving PDF to %s', pdfPath)
return pdf
.toFile(pdfPath)
.then(function(response){
var storage = {
local: pdfPath
}
var storagePluginPromises = []
for (var i in storagePlugins) {
// Because i will change before the promise is resolved
// we use a self executing function to inject the variable
export default async function documentPdfHandler(req: Request, res: Response) {
const { document } = req.body;
try {
const completionTrigger = new htmlPdf.CompletionTrigger.Timer(2000);
const documentHtml = generateHtmlFromDocument(document as any);
const { width, height } = document.pages[0] as PubPage;
const isLandscape = width > height;
const pdf = await htmlPdf.create(
`
${baseHtml}
<div>
${documentHtml}
</div>
`,
{
port: 9922,
completionTrigger,
printOptions: {
...basePrintOptions,
landscape: isLandscape,
paperWidth: isLandscape ? height : width,
paperHeight: isLandscape ? width : height,
toPdf() {
const renderOptions = {
completionTrigger: this.completionTrigger(),
printOptions: this.printOptions(),
host: 'localhost',
port: 9222
}
this.log(`Generating PDF for HTML string with options: ${JSON.stringify(renderOptions)}`)
return htmlPdf.create(this.htmlString, renderOptions)
}