来自:http://code.google.com/p/phantomjs/issues/detail?id=364
Version PhantomJS 1.3.0 What steps will reproduce the problem? 1. run phantomjs rasterize.js http://localhost/high_test_svg.html phantomjs_test_svg_png.pdf 2. I have attached a test html file with source images and output. What is the expected output? chart with no grayed out lines What do you see instead? graph lines are being grayed out Which operating system are you using? Linux version 2.6.18-238.19.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) Did you use binary PhantomJS or did you compile it from source? Compile from source Please provide any additional information below.
Jan 28, 2012
Thanks for taking a look at this, the patch will do the trick. While, researching this issue further, I also thought that tracking might be causing some of the difficulties, so in trying to isolate and simplify the re-creation of the issue, I created an additional svg file, with all the animations, tracking, and tooltips turned off, etc and it looks good. I also wrote a simple PyQt script that exports to pdf using the QWebView and QPrinter functions to try to isolate the issue may be. I have attached both files. Love phontom. Thanks. Thanks.
Jul 5, 2012
Just a note, I wouldn't be surprised if this is due to how certain CSS styles get overridden while printing (I've noticed that opacity gets set to 1.0 in other contexts).
Jan 24, 2013
This fix is one way to do it. It disables the shadows though. Another way would be to disable mousetracking in the options. The only problem I'm left with now is the shadow opacity. Any ideas? Here's an example http://jsfiddle.net/jvisser/aKJLv/ And use this command to rasterize: phantomjs examples/rasterize.js http://fiddle.jshell.net/jvisser/aKJLv/show/light/ output.pdf A4
Mar 15, 2013
Closing. This issue has been moved to GitHub: https://github.com/ariya/phantomjs/issues/10364
//
//
generate_pdf(保持页面原始大小).js
// This file is NOT a browser-run javascript but PhantonJS script
var system = require('system');
var address = system.args[1];
var output = system.args[2];
var page = require('webpage').create();
page.paperSize = {
format: 'A4',
orientation: 'landscape',
border: '1cm'
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit();
} else {
window.setTimeout(function () {
// Remove all low-opacity paths. see PhantomJS issue #364
page.evaluate(function () {
var paths = document.getElementsByTagName("path");
for (var i = paths.length - 1; i >= 0; i--) {
var path = paths[i];
var strokeOpacity = path.getAttribute('stroke-opacity');
if (strokeOpacity != null && strokeOpacity < 0.2)
path.parentNode.removeChild(path);
}
});
page.render(output);
phantom.exit();
}, 5000);
}
});
///
///
generate_pdf(rasterize的重写).jsgenerate_pdf(rasterize的重写).js
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: 1024, height: 768 };
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 () {
// Remove all low-opacity paths. see PhantomJS issue #364
page.evaluate(function () {
var paths = document.getElementsByTagName("path");
for (var i = paths.length - 1; i >= 0; i--) {
var path = paths[i];
var strokeOpacity = path.getAttribute('stroke-opacity');
if (strokeOpacity != null && strokeOpacity < 0.2)
path.parentNode.removeChild(path);
}
});
page.render(output);
phantom.exit();
}, 5000);
}
});
}
190 KB Download