我正在开发一个nodejs服务器,它将发布的html呈现为pdf、png或jpg。
(https://github.com/svenhornberg/pagetox https://github.com/svenhornberg/pagetox(server.js)如果你想尝试一下)
它工作得非常好,渲染复杂的网站,但仅限于我想要加载一个简单的图像。例如,我将以下代码发送到我的服务器:
<!doctype html>
<html>
<head>
<title>logo</title>
</head>
<body>
<img alt="logo" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png">
</body>
</html>
代码应该没问题。但渲染的响应图像不包含徽标图像。正如 phantomjs 文档中所述(http://phantomjs.org/api/webpage/property/settings.html http://phantomjs.org/api/webpage/property/settings.html) localToRemoteUrlAccessEnabled 设置为 false,因此将其设置为 true,如 phantom-node 文档中所述(https://github.com/sgentle/phantomjs-node/ https://github.com/sgentle/phantomjs-node/):
page.set('settings.localToRemoteUrlAccessEnabled', true);
page.set('settings.loadImages', true);
为了证明它被设置为 true,我调用了一个返回 true 的 getter
page.get('settings.localToRemoteUrlAccessEnabled', function(data) { console.log(data);});
我在 Linux 上使用 Node v0.10.26 和 phantomjs-node (0.6.1)、phantomjs(1.9.7)
现在的问题是,有人看到错误吗?或者可以给我提示我做错了什么。或者 phantomjs/phantom-node 不加载任何外部图像的任何其他可能性
我正在使用 render 方法生成 png、jpg 或 pdf 文件。我将评估函数内的方法作为回调调用,因此该网站应该完全加载。
(完整代码位于https://github.com/svenhornberg/pagetox/blob/master/server.js https://github.com/svenhornberg/pagetox/blob/master/server.js)
Edit1:我不在代理后面,这可能会阻止请求。