Created
December 3, 2012 21:05
-
-
Save booyaa/4198029 to your computer and use it in GitHub Desktop.
pocket calendar - generates a pdf from calendar year
This file contains hidden or 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
#!/usr/bin/env node | |
// kinda works | |
// npm modules: pdfkit | |
// pre-req is a calendar file: ncal -y > 2012.txt | |
// usage ./readCal.js | |
var fs = require('fs') | |
, path = require('path') | |
, PDFDocument = require('pdfkit') | |
, doc = new PDFDocument; | |
if (process.argv.length === 2) { | |
console.log('error! you must provide a text file!'); | |
process.exit(1); | |
} | |
var file = process.argv[2] | |
, basename = path.basename(file, path.extname(file)); | |
if (! fs.existsSync(file)) { | |
console.log('error! %s does not exist!', file); | |
process.exit(2); | |
} | |
fs.readFile(file, 'utf-8', function(err, data) { | |
if (err) throw err; | |
console.log('%d %s', Math.floor(Math.random(5)*5), data); | |
doc.font('Courier') | |
.fontSize(5) | |
.text(data); | |
doc.write(basename + '.pdf'); | |
}); | |
process.on('exit', function() { | |
console.log('mini calendar created: %s.pdf', basename); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment