Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am not able to export html page to pdf using phantomjs . When i click on export buttion the pdf file is getting opening with loginredirect page. pls find my below code.
help me on this asap.thanks.
var page = require('webpage').create(),
system = require('system');


console.log(system.args);

if (system.args.length !== 5) {
console.log('Usage: exporter.js targetUrl cookieValue cookieValidOnHostName exportFilePath');
phantom.exit(1);
} else {
url = system.args[1];
cookieValue = system.args[2];
cookieValidOnHostName = system.args[3];
exportFilePath = system.args[4];


// Lets set the cookie to expire after 24 hrs. This would not be a problem as the user might logout/navigate to a different page which will reset the expiry time
// 1000 * 60 * 60 * 24 = 86400000
phantom.addCookie({
'name': '.ASPXAUTH',
'value': cookieValue,
'domain': cookieValidOnHostName,
'path':'/',
'expires' : (new Date()).getTime() + (86400000)
});
page.paperSize = { format: 'A4', orientation: 'portrait', margin: '1cm' }
page.open(url, function (status) {
console.log('Status: '+status);
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
} else {
window.setTimeout(function () {
page.render(exportFilePath, {format: 'pdf'});
phantom.exit(0);
}, 1000);
}
});
}

this javascript file.

ReportExportCommandRunner.getExportedReportPath(url, Request.Cookies[".ASPXAUTH"].Value, Request.Url.Authority);
like dis passing cookie.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900