Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
fixes #24 support setting zoom level
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Ebdrup committed Mar 2, 2015
1 parent ecdffae commit 0dce6be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/rasterize/rasterize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var page = require('webpage').create();
var system = require('system');
var address, output, size;

if (system.args.length < 3 || system.args.length > 6) {
console.log('Usage: rasterize.js URL filename paperwidth*paperheight|paperformat portrait|landscape margin');
if (system.args.length < 3 || system.args.length > 7) {
console.log('Usage: rasterize.js URL filename paperwidth*paperheight|paperformat portrait|landscape margin zoomfactor');
console.log(' paperwidth*paperheight|paperformat examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
console.log(' margin examples: "1cm", "2in"');
phantom.exit(1);
Expand All @@ -17,7 +17,7 @@ if (system.args.length < 3 || system.args.length > 6) {
size.length === 2 ?
{ width: size[0], height: size[1], orientation: system.args[4], margin: system.args[5] } :
{ format: system.args[3], orientation: system.args[4], margin: system.args[5] };

page.zoomFactor = Number(system.args[6]);
var statusCode;

page.onResourceReceived = function (resource) {
Expand Down
9 changes: 8 additions & 1 deletion lib/webservices/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (process.platform !== 'darwin') {
var FORMATS = ['A3', 'A4', 'A5', 'Legal', 'Letter', 'Tabloid'];
var ORIENTATIONS = ['portrait', 'landscape'];
var marginRegExp = /^\d+(in|cm|mm)$/;
var zoomRegExp = /^\d(\.\d{1,3})?$/;

module.exports = function (app) {
app.get('/', function (req, res, next) {
Expand Down Expand Up @@ -45,6 +46,11 @@ module.exports = function (app) {
if(!marginRegExp.test(margin)){
return res.status(400).send(format('Invalid margin, the following formats are supported: 0cm, 1cm, 2cm, 1in, 13mm'));
}
var zoom = req.query.zoom || '1';
if(!zoomRegExp.test(zoom)){
return res.status(400).send(format('Invalid zoom, the following kind of formats are supported: 1, 0.5, 9.25, 0.105'));
}

request.head(url, function (err, resp) {
if (err) {
return res.status(400).send(format('Cannot get %s: %s', url, err.message));
Expand Down Expand Up @@ -73,7 +79,8 @@ module.exports = function (app) {
tmpFile,
paperFormat,
orientation,
margin
margin,
zoom
];
var pdfProcess = spawn(pdfExecutable, options);
pdfProcess.stdout.on('data', function (data) {
Expand Down
5 changes: 5 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ <h2>Querystring parameters</h2>
<td>portrait | landscape</td>
<td>The page orientation of the pdf generated</td>
</tr>
<tr>
<td><code>zoom</code></td>
<td>1 | 0.1 | 0.25 | 3.75 | 5.125</td>
<td>The zoom factor of the page. This makes the content larger or smaller.</td>
</tr>
<tr>
<td><code>download</code></td>
<td>true | false</td>
Expand Down

0 comments on commit 0dce6be

Please sign in to comment.