shadonar
shadonar

Reputation: 1194

phantomjs rasterize has problems with url parameters

I'm on a windows machine using the standard commandline tool and using PhantomJS and a modified rasterize.js code. The problem I have is when I pass the url, http://time.com/3274245/e-cigarettes-debate/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+time/topstories+(TIME:+Top+Stories). I've redirected the StandardOutput and the StandardError and here's what I get with the above url.

StandardOutput

Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]
  paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"

StandardErrror

'utm_source' is not recognized as an internal or external command,
operable program or batch file.
'utm_medium' is not recognized as an internal or external command,
operable program or batch file.
'utm_campaign' is not recognized as an internal or external command,
operable program or batch file.

So the question is, Is there any way resolve the problem with the parameters in the url?

Please let me know if there is any information that is missing or if anything needs to be clarified.

I'll add my modified rasterize.js below.

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

page.settings.userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:31.0) Gecko/20100101 Firefox/31.0';
if (system.args.length < 3 || system.args.length > 5) {
    console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
    console.log('  paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
    phantom.exit(1);
} else {
    address = system.args[1];
    output = system.args[2];
    page.viewportSize = { width: 1200, height: 1200 };
    if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
        size = system.args[3].split('*');
        page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
                                           : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
    }
    if (system.args.length > 4) {
        page.zoomFactor = system.args[4];
    }
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
            phantom.exit();
        } else {
            window.setTimeout(function () {
                page.render(output);
                phantom.exit();
            }, 10000);
        }
    });
}

Upvotes: 1

Views: 1919

Answers (1)

Artjom B.
Artjom B.

Reputation: 61892

In windows cmd you need to use quotes around parameters that might have special characters. A = is a good candidate for when something breaks.

phantomjs rasterize.js "http://time.com/..." time.png

For this page specifically you might need to disable web security:

phantomjs --web-security=false rasterize.js "http://time.com/..." time.png

Upvotes: 5

Related Questions