简体   繁体   English

chrome中的window.print强制单独页面不起作用

[英]window.print in chrome forced separate page not working

Hi i searched a lot but i can't find any answer.I just want forced separate print in chrome.I have two tables in my print page.i want them to print in seperate pages.So far I tried this 嗨,我搜索了很多东西,但找不到任何答案。我只想在chrome中强制进行单独打印。我的打印页面中有两个表格。我希望它们在单独的页面中打印。到目前为止,我已经尝试过

<?php
$htmlTable='<TABLE>
<TR>
    <TD>Name:</TD>
    <TD>Sanooj</TD>
</TR>
<TR>
    <TD>Email:</TD>
    <TD>SSJ$SANOOJ@gmail.com</TD>
</TR>
<TR>
    <TD>URl:</TD>
    <TD>wwww.google.com</TD>
</TR>
<TR>
    <TD>Comment:</TD>
    <TD>hello</TD>
</TR>
</TABLE>';
echo $htmlTable;
?>
<div style="page-break-after: always;"></div>
<?php
echo $htmlTable;
?>
<script type="text/javascript">
window.print();
setTimeout("window.close()", 50);
</script>

But when i use page-break-after: always; 但是当我使用page-break-after: always; it shows two pages in print preview but print comes out as one.If there is a solution please answer. 它在打印预览中显示两页,但打印为一页。如果有解决方案,请回答。

Note:If you think using FPDF is better then i am ok, but problem is i need print directly from browser like when i click button it shows print preview page and print it.When I use FPDF it shows browser preview page then print preview page then prints.So i need to be fast like window.print method. 注意:如果您认为使用FPDF更好,那我可以,但是问题是我需要直接从浏览器进行打印,例如当我单击按钮时它会显示打印预览页面并打印它。当我使用FPDF时它会显示浏览器预览页面然后打印预览页面然后打印。所以我需要像window.print方法一样快速。

'window.print' is a client side script for print. “ window.print”是用于打印的客户端脚本。 It's behavior is depends on the browser used .If you use it in chrome it behaves like chrome printing Or if yo use it in mozilla it behaves like mozilla printing. 它的行为取决于所使用的浏览器。如果在chrome中使用它,则其行为类似于chrome印刷;如果在mozilla中使用它,则其行为类似于mozilla印刷。 You can't customize those changes in general. 您通常无法自定义这些更改。

Maybe you miss the CSS 也许您错过了CSS

@media print
{
      .page-break  { display:block; page-break-before:always; }

}

This works for me..pls checkout 这对我有用..pls结帐

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM