-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdfify
More file actions
executable file
·34 lines (29 loc) · 1.05 KB
/
pdfify
File metadata and controls
executable file
·34 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/phantomjs
"use strict";
var page = require('webpage').create(),
system = require('system'),
address = system.args[1],
output = system.args[2],
paperSize;
// no idea why this produces a portrait page-sized viewport, but it does:
page.viewportSize = { width: 850, height: 625 };
page.zoomFactor = 0.8;
paperSize = { format: "A4", orientation: 'portrait', margin: '0.75in', width: "8.5in", height: "11in" };
if(system.args.length > 3) { page.zoomFactor = system.args[3]; }
if(system.args.length > 4) { paperSize.format = system.args[4]; }
page.paperSize = paperSize;
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the input URI', status);
phantom.exit(1);
} else {
window.setTimeout(function () {
var zoom = page.zoomFactor;
page.evaluate(function(zoom) {
return document.querySelector('body').style.zoom = zoom;
}, zoom);
page.render(output);
phantom.exit();
}, 200);
}
});