我正在尝试使用幻影将页面转换为,并且输出图像在底部被切断(图像不显示完整的HTML页面)。
PhantomJS
这是我的rasterize.js代码
var page = require('webpage').create(),
system = require('system'),
address, output, size;
address = system.args[1];
output = system.args[2];
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});,我按照以下方式运行它:
phantomjs ./rasterize.js ./test.html ./test.jpgHTML
我试图导出的HTML页面使用乔金特,它将SVGs绘制到页面上,因此它包含一个<svg>标记以及<g>标记,然后添加一些普通的<div>、<table>等标记。
下面是HTML页面中的一些示例:
...
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="v-2" width="3100" height="1101" visibility="shown">
<defs id="v-4">
<linearGradient id="linearGradientv-2-107112646">
<stop offset="0%" stop-color="rgb(228,234,243)" stop-opacity="1"/>
<stop offset="60%" stop-color="rgb(201,212,231)" stop-opacity="1"/>
</linearGradient>
...
<g id="j_1" model-id="86b320b6-0e8a-4dee-8258-e329b97c04ea" class="element custom Device" magnet="false" fill="#FFFFFF" stroke="none" transform="translate(50,100)">
<g class="rotatable" id="v-6" transform="rotate(0,150,20)">
<g class="scalable" id="v-47" transform="scale(2,0.16)">
<rect class="body" id="v-13" fill="url(#linearGradientv-2-107112646)" width="150" height="250" stroke="black"/>
</g>
...
</svg>当在浏览器中查看输入的HTML页面时,视图/中的整个页面在HTML 中什么都不会被切断。
图像
生成的图像显示了HTML页面中的<table>,但是它被切断了!整张桌子都会显示出来。它应该上升到"e",而不是切断"d“行之一。在实际的HTML页面(在浏览器中查看)中,表被正确显示并上升到"e":

有人知道为什么我的形象被切断了吗?
发布于 2017-01-26 20:05:20
,原来它是一个jointJS问题,而不是一个PhantomJS问题!对于那些可能发现这个问题的人,,我仍然会发布解决方案。
当用户移动或创建一个元素时,可以在画布上创建它。所以我听“鼠标指针向上”事件,并检查它是否脱离画布。如果它开了,我就把画布展开。JointJS代码现在看起来如下所示:
paper.on('cell:pointerup', function(cellView, evt, x, y) {
if(x>(paper.options.width-150))
{
paper.setDimensions((paper.options.width+200),paper.options.height);
}else if(y>paper.options.height)
{
paper.setDimensions(paper.options.width,(paper.options.height+200));
}
});https://stackoverflow.com/questions/41728729
复制相似问题