我有一个HTML报告,需要打印的景观,因为许多列。是否有一种方法可以做到这一点,而不需要用户更改文档设置?
浏览器中有哪些选项。
我有一个HTML报告,需要打印的景观,因为许多列。是否有一种方法可以做到这一点,而不需要用户更改文档设置?
浏览器中有哪些选项。
当前回答
引用自css - discussion Wiki
The @page rule has been cut down in scope from CSS2 to CSS2.1. The full CSS2 @page rule was reportedly implemented only in Opera (and buggily even then). My own testing shows that IE and Firefox don't support @page at all. According to the now-obsolescent CSS2 spec section 13.2.2 it is possible to override the user's setting of orientation and (for example) force printing in Landscape but the relevant "size" property has been dropped from CSS2.1, consistent with the fact that no current browser supports it. It has been reinstated in the CSS3 Paged Media module but note that this is only a Working Draft (as at July 2009). Conclusion: forget about @page for the present. If you feel your document needs to be printed in Landscape orientation, ask yourself if you can instead make your design more fluid. If you really can't (perhaps because the document contains data tables with many columns, for example), you will need to advise the user to set the orientation to Landscape and perhaps outline how to do it in the most common browsers. Of course, some browsers have a print fit-to-width (shrink-to-fit) feature (e.g. Opera, Firefox, IE7) but it's inadvisable to rely on users having this facility or having it switched on.
其他回答
我面临的问题可能和你一样。这里的每个人都使用CSS来静态地提供它,但我不得不寻找一个动态的解决方案,这样它就会根据活动元素而改变,而无需重新加载页面。
我创建了两个文件,肖像。css和风景。css。
Portrait.css是空的,但是landscape.css只有一行。
@media print{@page {size: landscape}}
在我的主文件中,我添加了这一行html来指定portrait.css为默认值。
<link rel="stylesheet" id="PRINTLAYOUT" href="portrait.css" type="text/css" /></link>
现在,要切换,你只需要改变元素中的href来切换打印模式。
$("#PRINTLAYOUT").attr("href","landscape.css")
// OR
document.getElementById("PRINTLAYOUT").href = "landscape.css" // I think...
这对我来说很有效,我希望它能帮助其他人像我一样做艰难的事情。注意,$表示JQuery..如果你还没有使用它,我强烈建议你现在就开始使用。
如前所述,size属性是您所需要的。要在打印时设置页面的方向和大小,您可以使用以下命令:
/* ISO Paper Size */
@page {
size: A4 landscape;
}
/* Size in mm */
@page {
size: 100mm 200mm landscape;
}
/* Size in inches */
@page {
size: 4in 6in landscape;
}
下面是@page文档的链接。
-webkit-transform: rotate(-90deg); -moz-transform:rotate(-90deg);
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
在Firefox 16.0.2中不能运行,但在Chrome中可以运行
<style type="text/css" media="print">
.landscape {
width: 100%;
height: 100%;
margin: 0% 0% 0% 0%; filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=1);
}
</style>
如果你想把这个样式应用到一个表格上,那么就用这个样式类创建一个div标签,并在这个div标签中添加table标签,最后关闭div标签。
此表格将仅以横向模式打印,所有其他页面将仅以纵向模式打印。但问题是,如果表的大小大于页面宽度,那么我们可能会丢失一些行,有时也会丢失标题。小心些而已。
祝你有愉快的一天。
谢谢你,亲爱的 Naveen Mettapally。
你可以尝试以下方法:
@page {
size: auto
}