0

When a get request is sent to: 'http://localhost:4000/features' There is a response with JSON Data which has HTML inside it.

I need the contents of the field name and description to be saved as PDF

Sample:

[{"_id":"5ad4951d0ba1c37c65818bc7","name":"Find your work faster","description":"<p>With an improved <strong>quick search</strong>, searching through all your issues and projects will be nothing else but a breeze. Whether you know the full issue key, part of the issue name, or just have a distant memory of a project from a year ago, start typing the words, and we&rsquo;ll do the rest for you. The quick search instantly shows the most relevant results, and refreshes them whenever you change your search term.</p>\n\n<p><img alt=\"\" src=\"https://confluence.atlassian.com/jirasoftware/files/945521251/945528523/1/1518181922686/quicksearch.png\" style=\"height:400px; width:800px\" /></p>\n\n<p>If you&rsquo;ve already found what you were looking for, just treat quick search as a handy work diary. Click anywhere in the box to see the issues and projects you&rsquo;ve been working on recently, and have the most important work always at your fingertips.</p>\n\n<p><a href=\"https://confluence.atlassian.com/jirasoftwareserver/quick-searching-939938728.html\">Learn more</a></p>\n","__v":0},{"_id":"5ad5ddddcd054b2b5b20143c","name":"Project sidebar","description":"<p>The project sidebar that we previewed in&nbsp;<a href=\"https://confluence.atlassian.com/jira/jira-6-4-release-notes-678561444.html\">JIRA 6.4</a>&nbsp;is here to stay. We built this new navigation experience to make it easier for you to find what you need in your projects. It&#39;s even better, if you are using JIRA Agile: your backlog, sprints, and reports are now just a click away. If you&#39;ve used the sidebar with JIRA Agile before, you&#39;ll notice that cross-project boards, which include multiple projects, now have a project sidebar as well &mdash;&nbsp;albeit a simpler version.</p>\n","__v":0}]

Can this be done in nodeJS?

Lars Suffys
  • 129
  • 1
  • 4
  • 13

2 Answers2

0

Conversion isn't the right word but generation is. According to the generalized response in json response you can write logic for generation of pdf from it in node-js server. PDFKit and PDFmake are two good libraries for this purpose. I've used pdfmake and is very good. See doc here: https://pdfmake.github.io/docs/

0

Use html-pdf to generated PDF from html, Where it works on top of phantom

var pdf = require('html-pdf');
pdf.create(file[0].description).toFile('./' + file[0].description + '.pdf', function (err, res) {
    console.log(res.filename);
});

Note : Sample code snippet above to handle first object in your array

Şivā SankĂr
  • 1,966
  • 1
  • 18
  • 34