Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ prototype2pdf is a command line tool that takes a list of URLs for a prototype a

## Dependencies

- [webkit2png](http://www.paulhammond.org/webkit2png/)
- [PhantomJS](http://phantomjs.org/)
- [ImageMagick](http://www.imagemagick.org)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImageMagick is still required to stitch the screenshots into a PDF

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.


Both can be installed using [Homebrew](http://brew.sh):
On Mac OS X, this can be installed via [Homebrew](http://brew.sh):

```
brew install webkit2png imagemagick
brew install phantomjs
```

On debian-type systems, this can be installed via apt:

```
sudo apt-get install phantomjs
```

## Usage
Expand Down
26 changes: 26 additions & 0 deletions phantom-screenshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env phantomjs


var page = require('webpage').create(),
system = require('system'),
address;

if (system.args.length != 3) {
console.log('Usage: ' + system.args[0] + ' <some URL> <width in pixels>');
phantom.exit();
}

page.viewportSize = {
width: system.args[2],
height: 768
};

address = system.args[1];
page.open(address, function(status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
page.render(address.replace(/[^a-z0-9]/gi, '_').toLowerCase() + '.png');
}
phantom.exit();
});
5 changes: 4 additions & 1 deletion prototype2pdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

THIS_SCRIPT=$0
THIS_DIR=$(dirname "${THIS_SCRIPT}")

# check if there are already PNGs here, and bail if there are
ls *.png > /dev/null 2>&1
if [ "$?" -eq "0" ]
Expand All @@ -9,7 +12,7 @@ then
fi

while read url; do
webkit2png --fullsize --scale=1 --width=${1:-320} --clipwidth=1 $url > /dev/null
${THIS_DIR}/phantom-screenshot.js $url ${1:-320} > /dev/null
done

convert *.png +repage -crop 1090x1603 +repage -units PixelsPerInch -density 150x150 -extent 1090x1603 -bordercolor transparent -border 75x75 pdf:-
Expand Down