Created
August 11, 2017 10:49
-
-
Save vgvinay2/6b185c2ac857648103ec42a789f78704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[11/08/17, 4:18:11 PM] Saurabh Kumar: 'use strict'; | |
const xml2js = require('xml2js').parseString; | |
const js2xmlparser = require("js2xmlparser"); | |
const PDFDocument = require('pdfkit'); | |
const fs= require('fs'); | |
var doc = new PDFDocument(); | |
const tableify = require('tableify'); | |
//question 1 | |
const jsonData = { note: | |
{ to: [ 'Tove' ], | |
from: [ 'Jani' ], | |
heading: [ 'Reminder' ], | |
body: [ 'Dont forget me this weekend!' ] | |
} | |
}; | |
const data = js2xmlparser.parse("data", jsonData) | |
console.log('XML data: ', data); | |
//question 2 | |
const xmlData = '<?xml version="1.0" encoding="UTF-8"?>' + | |
'<note>' + | |
'<to>Tove</to>' + | |
'<from>Jani</from>' + | |
'<heading>Reminder</heading>' + | |
'<body>Dont forget me this weekend!</body>' + | |
'</note>'; | |
xml2js(xmlData, function (err, result) { | |
if(err) | |
console.log('Error: ', err); | |
else | |
console.log('Json data: ', result); | |
}); | |
//question 3 | |
var tableData = tableify({ | |
someArrayOfObjects : [ | |
{ a : 1, b : 2, c : 3 } | |
, { a : 2, b : 3, c : 4 } | |
, { a : 3, b : 4, c : 5 } | |
] | |
}); | |
fs.writeFile('demo.html',tableData,(err)=>{ | |
if (err) { | |
console.error(err); | |
} else { | |
console.log("Data written successfully in file!"); | |
} | |
}) ; | |
//question 4 | |
doc.pipe(fs.createWriteStream('output.pdf')) ; | |
doc.fontSize(25) | |
.text('Some text for demo') | |
doc.end(); | |
[11/08/17, 4:18:43 PM] Vinay Gupta: :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment