Created
July 29, 2016 19:26
-
-
Save devintyler/b5591959c73befe352822ba5492954ea 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
var pdf = require('html-pdf'); | |
var fs = require('fs'); | |
// Syncano | |
var Syncano = require("syncano"); // CommonJS | |
var connection = Syncano({accountKey: CONFIG.account}); | |
var DataObject = connection.DataObject; | |
var className = 'CLASS'; | |
var html = ""; // html to generate pdf | |
var options = { format: 'Letter' }; // formatting options | |
var pdfData = ''; // final pdf data | |
html = '<!doctype html><html lang="en">'+ | |
'<body>'+ | |
'<div id="pageHeader">Default header</div>'+ | |
'<div><p>Content</p></div>'+ | |
'<div id="pageFooter">Default footer</div>'+ | |
'</body></html>'; | |
pdf.create(html, options).toStream(function(err, stream){ | |
stream.pipe(fs.createWriteStream('test.pdf')); | |
stream.on('end', function () { | |
var readStream = fs.createReadStream('test.pdf'); // if you want to read it back | |
readStream.on('data', function(chunk){ | |
pdfData+=chunk; | |
}); | |
readStream.on('end', function(){ | |
console.log("Done creating PDF."); | |
createObject(); | |
}); | |
}); | |
}); | |
function createObject() { | |
var object = { | |
pdf: Syncano.file('test.pdf'), | |
instanceName: META.instance, | |
className: className | |
}; | |
DataObject.please().create(object).then(function(object) { | |
console.log("File uploaded here: " + object.pdf.value); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment