pdfcreator.js 653 B

12345678910111213141516171819202122
  1. var temp = require('../lib/temp'),
  2. fs = require('fs'),
  3. util = require('util'),
  4. path = require('path'),
  5. exec = require('child_process').exec;
  6. var myData = "\\starttext\nHello World\n\\stoptext";
  7. temp.mkdir('pdfcreator', function(err, dirPath) {
  8. var inputPath = path.join(dirPath, 'input.tex')
  9. fs.writeFile(inputPath, myData, function(err) {
  10. if (err) throw err;
  11. process.chdir(dirPath);
  12. exec("texexec '" + inputPath + "'", function(err) {
  13. if (err) throw err;
  14. fs.readFile(path.join(dirPath, 'input.pdf'), function(err, data) {
  15. if (err) throw err;
  16. util.print(data);
  17. });
  18. });
  19. });
  20. });