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

Commit 0dce6be

Browse files
author
Allan Ebdrup
committed
fixes #24 support setting zoom level
1 parent ecdffae commit 0dce6be

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

lib/rasterize/rasterize.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ var page = require('webpage').create();
22
var system = require('system');
33
var address, output, size;
44

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

2323
page.onResourceReceived = function (resource) {

lib/webservices/pdf.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (process.platform !== 'darwin') {
1717
var FORMATS = ['A3', 'A4', 'A5', 'Legal', 'Letter', 'Tabloid'];
1818
var ORIENTATIONS = ['portrait', 'landscape'];
1919
var marginRegExp = /^\d+(in|cm|mm)$/;
20+
var zoomRegExp = /^\d(\.\d{1,3})?$/;
2021

2122
module.exports = function (app) {
2223
app.get('/', function (req, res, next) {
@@ -45,6 +46,11 @@ module.exports = function (app) {
4546
if(!marginRegExp.test(margin)){
4647
return res.status(400).send(format('Invalid margin, the following formats are supported: 0cm, 1cm, 2cm, 1in, 13mm'));
4748
}
49+
var zoom = req.query.zoom || '1';
50+
if(!zoomRegExp.test(zoom)){
51+
return res.status(400).send(format('Invalid zoom, the following kind of formats are supported: 1, 0.5, 9.25, 0.105'));
52+
}
53+
4854
request.head(url, function (err, resp) {
4955
if (err) {
5056
return res.status(400).send(format('Cannot get %s: %s', url, err.message));
@@ -73,7 +79,8 @@ module.exports = function (app) {
7379
tmpFile,
7480
paperFormat,
7581
orientation,
76-
margin
82+
margin,
83+
zoom
7784
];
7885
var pdfProcess = spawn(pdfExecutable, options);
7986
pdfProcess.stdout.on('data', function (data) {

public/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ <h2>Querystring parameters</h2>
303303
<td>portrait | landscape</td>
304304
<td>The page orientation of the pdf generated</td>
305305
</tr>
306+
<tr>
307+
<td><code>zoom</code></td>
308+
<td>1 | 0.1 | 0.25 | 3.75 | 5.125</td>
309+
<td>The zoom factor of the page. This makes the content larger or smaller.</td>
310+
</tr>
306311
<tr>
307312
<td><code>download</code></td>
308313
<td>true | false</td>

0 commit comments

Comments
 (0)