关于WebBrowser.ExecWB分页打印的奇怪问题
如果代码是纯HTML的,如:
<html><title>JS 分页批量打印解决方案(只支持IE)</title><script language="javascript"> function printWithAlert() { document.all.WebBrowser.ExecWB(6,1); } function printWithoutAlert() { PageSetup_Null(); document.all.WebBrowser.ExecWB(6,6); } function printSetup() { document.all.WebBrowser.ExecWB(8,1); } function printPrieview() { document.all.WebBrowser.ExecWB(7,1); } function printImmediately() { document.all.WebBrowser.ExecWB(6,6); window.close(); }</script><OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 style="display:none"></OBJECT></noscript><style media=print> .Noprint{display:none;} .PageNext{page-break-after: always;} </style><table align="center" class=NOPRINT> <tr> <td align="center"><BUTTON title=打印 onclick=printWithAlert()>打印</BUTTON> <BUTTON title=直接打印 onclick=printWithoutAlert()>直接打印</BUTTON> <input type=button value="打印设置" onClick="printSetup()" > <button onclick ='printPrieview()' title='打印预览...' >打印预览</button></td> </tr></table><div class=NOPRINT> 以下为打印区:<br></div><hr size=1 noshadow color=black class=NOPRINT ><table class="PageNext" > <tr> <td colspan=2><h1 id="nbsp-第一页的内容-nbsp-nbsp"> 第一页的内容 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 </h1> </td> </tr></table><hr size=1 noshadow color=black class=NOPRINT ><div class="PageNext"><h1 id="第二页内容">第二页内容2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222</h1></div><hr size=1 noshadow color=black class=NOPRINT ><h1 id="第三页内容">第三页内容</h1></html>
这样可以看到能够正确分页
但是如果内容是PHP动态生成的,打印预览是不会分页的,但是右键查看源代码,生成的HTML文件和手写的一样,但是就是不能分页,好奇怪的问题。
大家可以写段简单的PHP代码测试一下,让PHP循环生成上面的内容,即使看HTML代码完全一样,也不会分页,如果在代码中不能分页打印,那么就没有任何意义了,因为很多数据都是从数据库中读取然后由程序生成的~~~~~~~~~~~
希望知道如何解决这个问题的前辈指点,谢谢。晕了两天了,搞不懂怎么回事
回复讨论(解决方案)
因为只支持IE,所以测试的意义不大
主要是找的这个控件只支持IE,没办法啊,找不到别的打印控件
您有推荐的吗?支持分页、打印预览什么的。
或者你清楚这是怎么回事吗?程序生成的死活不分页,如果把程序的页面另存为html,然后打开也能正常分页,郁闷死了
做各TABLE 直接PRINT吧
做各TABLE 直接PRINT吧
那你说的就只能一个一个的打印了,如果从数据库读了100条数据,程序自动生成100个表格,如果能分页的话,会自动打印100页;
否则,只能一页一页的打印,打印100次~~~~~
可以试试这些 http://www.baidu.com/baidu?word=web%E9%A1%B5%E9%9D%A2%E6%89%93%E5%8D%B0%E6%8E%A7%E4%BB%B6&ie=utf-8
用其他控件不失为一个解决方法,但是出现这种情况到底是怎么回事呢?
非常奇怪的问题,希望大家研究一下
既然你坚持,我就陪你玩玩
测试了一下,并没有发现你说的现象
既然你坚持,我就陪你玩玩
测试了一下,并没有发现你说的现象
好负责的版主!
套马杆的汉子你威武雄壮!
测试了一下,发现问题根源了:
如果是php代码生成的:
<html><head><title>web打印</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css" media="print"> .noprint{display:none;} .pagenext{page-break-after:always;} </style><script language="javascript"> function printWithAlert() { document.all.WebBrowser.ExecWB(6,1); } function printWithoutAlert() { PageSetup_Null(); document.all.WebBrowser.ExecWB(6,6); } function printSetup() { document.all.WebBrowser.ExecWB(8,1); } function printPrieview() { //PageSetup_Null(); document.all.WebBrowser.ExecWB(7,1); } function printImmediately() { document.all.WebBrowser.ExecWB(6,6); window.close(); }</script></head><body><OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 style="display:none"></OBJECT><!--浮动控制层:数据筛选和打印--><div id="floatctl" class="noprint"><input type="button" value="打印预览" onclick="printPrieview();"/><input type="button" value="直接打印" onclick="window.print() ;" /></div><br /><br /><?phpfunction gentable($pagenum){ echo '<table width="860" border="1" cellpadding="0" cellspacing="0" style="page-break-after: always">'; echo '<tr><td align="center"><h1 id="WEB分页打印-nbsp">WEB分页打印 </h1></td></tr><tr><td>'; echo '<table width="100%" class="tab1"><tr><td>这是第'.$pagenum.'页</td></tr>'; echo '</table>'; echo '</td></tr></table>';} for($i=0;$i<10;$i++) { gentable($i+1); }?></body></html>
确实没有问题,但是如果一个页面iframe src=这个页面,就不能正确分页:
<html><head><title>测试iframe分页</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link href="images/style.css" type="text/css" rel="stylesheet"><style type="text/css" media="print"> .noprint{display:none;} .print{display:block;}.pagenext{page-break-after: always;} </style></head><body><!--这个test.php就是上面的代码--><iframe src="test.php" width="100%" height="100%"></iframe></body></html>
如果这样,就不能正确分页了
这也算解决问题了,但是请问这是怎么回事呢?是控件的问题吗?
既然你坚持,我就陪你玩玩
测试了一下,并没有发现你说的现象
http://bbs.csdn.net/topics/390443315
这也是我的帖子,版主请回复一下,把分给你

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
