Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. app.get('/pdfs', function (req, res) {
  2. let json = require ('./posts.json')
  3. let posts = []
  4. json.forEach(function (value, key, listObj)
  5. {
  6. posts.push(
  7. {
  8. userId: value.userId,
  9. id : value.id,
  10. title: value.title,
  11. body: value.body
  12. }
  13. )
  14. } );
  15.  
  16. conteudoPDF = {
  17. content: [
  18.  
  19. {text: 'Teste usando JSONPlaceholder', style: 'Header'},
  20. 'Tabela cotendo todos os posts do site JSON Placeholder',
  21. {
  22. table:{
  23. body:[
  24. [['Usuário'], ['Post'], ['Título'], ['Texto']],
  25. [
  26. posts.forEach(function (posts, err, results) {
  27. [[posts.userId], [posts.id],
  28. [posts.title], [posts.body]]
  29. if(err){
  30. res.json(err)
  31. }
  32. else{
  33. res.json(results)
  34. }
  35. },
  36. posts.push()
  37. )
  38. ]
  39. ],
  40. }
  41. }
  42. ]
  43. }
  44. let pdfDoc = printer.createPdfKitDocument(conteudoPDF);
  45. pdfDoc.pipe(fs.createWriteStream('../pdfs/testeJson.pdf'));
  46. console.log('Imprimiu!!');
  47. pdfDoc.end();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement