If you're deploying your app to somewhere where you can't be sure to have reliable disk read/write access, the normal strategy of writing to a temp-file doesn't work.
Instead we can open a pipe to the Phantom.js process, and then pass in the HTML via stdin
, and then have the rasterize.js
script write out the resulting PDF to stdout
, which we can then capture.
Any log messages from the Phantom.js process can be passed via stderr
if we want.
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
function log(msg) { | |
console.log(getTime()+ ': '+ msg); | |
} | |
function getTime() { | |
var d = new Date(); | |
return pad(d.getHours()) +':'+ pad(d.getMinutes()) +':'+ pad(d.getSeconds()) +'.'+ rpad(d.getMilliseconds(), 3); | |
} | |
function pad(val, len) { |
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
/** | |
* Run this with `babel-node generateSVG.js` | |
*/ | |
import fs from 'fs'; | |
import path from 'path'; | |
import { Readable } from 'stream'; | |
import childProcess from 'child_process'; | |
import phantomjs from 'phantomjs'; | |
import im from 'imagemagick'; | |
import tmp from 'tmp'; |
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
if (!Date.prototype.toISOString) { | |
Date.prototype.toISOString = function () { | |
function pad(n) { return n < 10 ? '0' + n : n; } | |
function ms(n) { return n < 10 ? '00'+ n : n < 100 ? '0' + n : n } | |
return this.getFullYear() + '-' + | |
pad(this.getMonth() + 1) + '-' + | |
pad(this.getDate()) + 'T' + | |
pad(this.getHours()) + ':' + | |
pad(this.getMinutes()) + ':' + | |
pad(this.getSeconds()) + '.' + |
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
# exporter.rb | |
# A very simple Ruby wrapper for PhantomJS | |
# for create PDF's or anything you can create with PhantomJS | |
require 'json' | |
class Exporter | |
class PhantomJSNotFound < StandardError; end | |
class << self | |
def default_options |
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 http = require('http'); | |
var url = require('url'); | |
var spawn = require('child_process').spawn, child; | |
var fs = require('fs'); | |
var util = require('util'); | |
var gm = require('gm'); | |
var ssh2 = require('ssh2'); | |
var debug = 1; // increase to increase verbosity | |
require('systemd'); |
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
/** | |
* AppCache audio tag caching fix main code | |
*/ | |
(function () { | |
//document.addEventListener("DOMContentLoaded", function () { | |
hashCode = function (str) { | |
var hash = 0; | |
if (str.length == 0) return hash; | |
for (var i = 0; i < str.length; i++) { | |
char = str.charCodeAt(i); |
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
require 'uri' | |
require 'cgi' | |
require 'openssl' | |
require 'base64' | |
module YBoss | |
class Oauth | |
attr_accessor :consumer_key, :consumer_secret, :token, :token_secret, :req_method, | |
:sig_method, :oauth_version, :callback_url, :params, :req_url, :base_str |