2016-11-28 51 views
1

如果我使用SVG拼贴作为网站的背景,在浏览器中查看时看起来很好,但如果打印,则会以奇怪的不均匀方式缩放。有没有办法让不失真浏览器打印用于打印的SVG背景图像拼贴

这方面的一个例子是here,它看起来像这样:

enter image description here

但在印刷看起来是这样的:

enter image description here

<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'> 
<rect width='10' height='10' fill='#fff'/> 
<rect width='5' height='5' fill='#ccc'/> 
</svg> 

#test { 
 
    height: 500px; 
 
    width:500px; 
 
    background: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCI+CjxyZWN0IHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCIgZmlsbD0iI2ZmZiI+PC9yZWN0Pgo8cmVjdCB3aWR0aD0iNSIgaGVpZ2h0PSI1IiBmaWxsPSIjY2NjIj48L3JlY3Q+Cjwvc3ZnPg=="); 
 
}
<div id="test"> 
 
</div>

的SVG是

+1

看起来像Chrome错误,在FF工作正常。你应该在他们的bug跟踪器上打开一个bug。 – Kaiido

回答

0

您可以使用SVGIMG标签和追加通过jQuery像下面摘录我希望帮助,这是对工作的罚款打印FF浏览器。

$(document).ready(function(){ 
 
\t var squareBox = 3000; //You can increase and descrease of square boxes 
 
\t for (var i = 1; i <= squareBox; i++) { 
 
\t \t $('#test').append('<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCI+CjxyZWN0IHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCIgZmlsbD0iI2ZmZiI+PC9yZWN0Pgo8cmVjdCB3aWR0aD0iNSIgaGVpZ2h0PSI1IiBmaWxsPSIjY2NjIj48L3JlY3Q+Cjwvc3ZnPg==">'); 
 
\t } 
 
})
#test{ 
 
height: 500px; 
 
width: 500px; 
 
overflow: hidden; 
 
} 
 
#test img{ 
 
width: 10px; 
 
height: 10px; 
 
display: block; 
 
float: left; 
 
margin-top: 0px; 
 
} 
 
@media print and (color){ 
 
*{ 
 
    -webkit-print-color-adjust: exact; 
 
    print-color-adjust: exact; 
 
} 
 
button{display: none;} 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<button type="button" onclick="window.print();">Print</button> 
 

 
<div id="test"></div>

+1

认真吗?用一吨img标签替换背景重复? – Kaiido

+0

是的,因为当我尝试通过css打印您的代码作为背景并打印时,这在打印视图中会出现在chrome上。所以如果你通过for循环重复多个相同的图像。我认为你的打印问题会解决。 –

+0

这不是我的,我不是OP,但是这样做很可能会造成很多内存问题... – Kaiido