有没有办法缩小我的SVG图形以适应打印页面,同时保留图形的Web版本?还是我在浪费时间?
我目前只能使用FF,但当然跨浏览器方法更好......
谷歌搜索建议"不"到1& 2,但很多帖子都很旧。
最新方法:
var svg = d3.select("div#matrix").append("svg")
.attr("width", 1000)
.attr("height", 1000)
//.attr("viewBox","0 0 500 500") - I don't want to apply this to the webpage SVG - this is just for testing
//.attr("preserveAspectRatio","xMinYMin meet")
.attr("id","matrixSVG")
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
将文本标签添加到图形后,我会调整网页的容器元素的大小:
var svgWidth = margin.left+margin.right+(cellSize*horizNodes.length);
var svgHeight = margin.top+margin.bottom+(cellSize*vertNodes.length);
d3.select("svg#matrixSVG").attr("width",svgWidth).attr("height",svgHeight);
d3.select("div#matrix").style("width",svgWidth+"px").style("height",svgHeight+"px");
CSS:
@media print {
svg#matrixSVG {
width: 175mm; //this is the max size to fit US letter and A4
height: 245mm;
}
}
感谢您的帮助