Closed franciscoffavaro closed 7 years ago
renderRecibo = (req, res, next) =>{ try{ var options = { format: 'A4' }; let html = pug.renderFile("../../views/recibo.pug", { title: 'Recibo de @Pagamento', image: '596f619cc9f73b0613594a49' }); pdf.create(html, options).toStream((err, stream)=>{ stream.pipe(res); }) }catch(e){ console.log(e) } }
this is the complete code.
Hi @franciscoffavaro, i use Pug in this example and it works perfect
Hi @cdiaz, it's the same code of i have in my app. The problem is, i have a method called renderRecido. I get a pug file and render to make a pdf file and show. But all time, the file path send me an error:
{ Error: ENOENT: no such file or directory, open '../../views/recibo.pug'
at Error (native)
at Object.fs.openSync (fs.js:641:18)
at Object.fs.readFileSync (fs.js:509:33)
at handleTemplateCache (/Users/franciscofavaro/Documents/Github/nest-backend/node_modules/pug/lib/index.js:215:37)
at Object.exports.renderFile (/Users/franciscofavaro/Documents/Github/nest-backend/node_modules/pug/lib/index.js:428:10)
at ImagesService.renderRecibo.e [as renderRecibo] (/Users/franciscofavaro/Documents/Github/nest-backend/src/modules/images/images.service.ts:31:22)
at ImagesController.getRecibo (/Users/franciscofavaro/Documents/Github/nest-backend/src/modules/images/images.controller.ts:14:26)
at e (/Users/franciscofavaro/Documents/Github/nest-backend/node_modules/@nestjs/core/router/router-proxy.js:7:33)
at Layer.handle [as handle_request] (/Users/franciscofavaro/Documents/Github/nest-backend/node_modules/@nestjs/core/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/franciscofavaro/Documents/Github/nest-backend/node_modules/@nestjs/core/node_modules/express/lib/router/route.js:131:13)
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '../../views/recibo.pug' }
Not found the file, but the path is right. I really don't know whats happening.
Hi again @cdiaz. I need to render a file, because i use their to generate a pdf file. The render File is save in a variable, and this variable is transformed in a pdf file.
renderRecibo = (req, res, next) =>{
try{
var options = { format: 'A4' };
let html = pug.renderFile('../../views/recibo.pug', {
title: 'Recibo de Pagamento',
nome: 'Francisco Favaro',
valor: '1234,56',
metragem: '200',
quadra: 'D36F',
numero: '02',
loteamento: 'Cidade Balneário Novo Mundo',
day: '01',
month: 'Janiero',
year: '2015',
valor_literal: 'Hum Mil Reais',
nome_empresa: 'ARQUING CONSULTORES LTDA-ME',
image: '596f619cc9f73b0613594a49'
});
pdf.create(html, options).toStream((err, stream)=>{
stream.pipe(res);
})
}catch(e){
console.log(e)
}
}
This is the complete code. I use the pug function to create a HTML file and send to screen in PDF format.
the only form to make this work is using the complete path... The simple solution is: let html = pug.renderFile('/Users/franciscofavaro/Documents/Github/nest-backend/src/views/recibo.pug', ...)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I need to use pug in my projects, and i have this problem:
If i use only Node, works, but in Nest no.
In main file of Nest, i have:
thanks for all help.