"缩小到页面"关于打印的SVG?

时间:2017-06-09 09:48:40

标签: javascript css svg media-queries

有没有办法缩小我的SVG图形以适应打印页面,同时保留图形的Web版本?还是我在浪费时间?

我目前只能使用FF,但当然跨浏览器方法更好......

  1. 是否有可以放入媒体的CSS版本的viewBox 查询?
  2. 我可以申请js中的onPrint事件吗? 视框?
  3. 任何其他方法 - javascript,css,jquery,d3 all 欢迎。
  4. 谷歌搜索建议"不"到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;
      }
    
     }
    

    感谢您的帮助

0 个答案:

没有答案