Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.get('/pdfs', function (req, res) {
- let json = require ('./posts.json')
- let posts = []
- json.forEach(function (value, key, listObj)
- {
- posts.push(
- {
- userId: value.userId,
- id : value.id,
- title: value.title,
- body: value.body
- }
- )
- } );
- conteudoPDF = {
- content: [
- {text: 'Teste usando JSONPlaceholder', style: 'Header'},
- 'Tabela cotendo todos os posts do site JSON Placeholder',
- {
- table:{
- body:[
- [['Usuário'], ['Post'], ['Título'], ['Texto']],
- [
- posts.forEach(function (posts, err, results) {
- [[posts.userId], [posts.id],
- [posts.title], [posts.body]]
- if(err){
- res.json(err)
- }
- else{
- res.json(results)
- }
- },
- posts.push()
- )
- ]
- ],
- }
- }
- ]
- }
- let pdfDoc = printer.createPdfKitDocument(conteudoPDF);
- pdfDoc.pipe(fs.createWriteStream('../pdfs/testeJson.pdf'));
- console.log('Imprimiu!!');
- pdfDoc.end();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement