var page = require('webpage').create(),
system = require('system'),
address, output, size;
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: 600, height: 600 };
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();
});
}
});
}
'use strict';
var guid = function () {
var uid = 0;
this.newId = function () {
uid = uid % 1000;
var now = new Date();
var utc = new Date(now.getTime() + now.getTimezoneOffset() * 60000);
return utc.getTime() + uid++;
}
}
exports.utils = {
guid: new guid()
};
'use strict';
var exec = require('child_process').exec;
var utils = require('./utils').utils;
var nodeUtil = require('util');
var outPut = function (id, req, res) {
var path = nodeUtil.format("tmp/%s.pdf", utils.guid.newId());
var port = req.app.settings.port;
var pdfUrl = nodeUtil.format("%s://%s%s/pdf/%s", req.protocol, req.host, ( port == 80 || port == 443 ? '' : ':' + port ), id);
exec(nodeUtil.format("phantomjs tool/rasterize.js %s %s A4", pdfUrl, path), function (error, stdout, stderr) {
if (error || stderr) {
res.send(500, error || stderr);
return;
}
res.set('Content-Type', 'application/pdf');
res.download(path);
});
};
exports.pdfUtils = {
outPut: outPut
};
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有