当用户需要打印两个控件的图纸时,可以采用嵌套打印实现。点击此处在线演示。
实现嵌套打印功能,首先将两个控件放入网页中,js代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<p align= "center" > <object classid= "clsid:74A777F8-7A8F-4e7c-AF47-7074828086E2" id= "MxDrawXCtrl1" codebase= "http://www.mxdraw.com/MxDrawX52.CAB#version=7.0.0.1" width=48% height=85% align= "left" > <param name= "_Version" value= "65536" > <param name= "_ExtentX" value= "24262" > <param name= "_ExtentY" value= "16219" > <param name= "_StockProps" value= "0" > <param name= "IsRuningAtIE" value= "1" > <param name= "EnablePrintCmd" value= "1" > <param name= "ShowStatusBar" value= "1" > <param name= "ShowMenuBar" value= "1" > <param name= "ShowToolBars" value= "1" > <param name= "ShowCommandWindow" value= "1" > <param name= "ShowModelBar" value= "1" > <param name= "Iniset" value= "AutoActive=N,LoadMrx=PropertyEditor" > <param name= "ToolBarFiles" value= "MxDraw-ToolBar.mxt,MxDraw-ToolBar-DrawParam.mxt,MxDraw-ToolBar-Draw.mxt,MxDraw-ToolBar-Edit.mxt" > <SPAN STYLE= "color:red" >不能装载CAD控件。请确认你可以连接网络或者检查浏览器的选项中安全设置。<a href= "http://www.mxdraw.com/MxDrawX52.msi" >http://www.mxdraw.com/MxDrawX52.msi 安载CAD控件</a></SPAN> </object> <object classid= "clsid:74A777F8-7A8F-4e7c-AF47-7074828086E2" id= "MxDrawXCtrl2" codebase= "http://www.mxdraw.com/MxDrawX52.CAB#version=7.0.0.1" width=48% height=85% align= "right" > <param name= "_Version" value= "65536" > <param name= "_ExtentX" value= "24262" > <param name= "_ExtentY" value= "16219" > <param name= "_StockProps" value= "0" > <param name= "IsRuningAtIE" value= "1" > <param name= "EnablePrintCmd" value= "1" > <param name= "ShowStatusBar" value= "1" > <param name= "ShowMenuBar" value= "1" > <param name= "ShowToolBars" value= "1" > <param name= "ShowCommandWindow" value= "1" > <param name= "ShowModelBar" value= "1" > <param name= "Iniset" value= "AutoActive=N,LoadMrx=PropertyEditor" > <param name= "ToolBarFiles" value= "MxDraw-ToolBar.mxt,MxDraw-ToolBar-DrawParam.mxt,MxDraw-ToolBar-Draw.mxt,MxDraw-ToolBar-Edit.mxt" > <SPAN STYLE= "color:red" >不能装载CAD控件。请确认你可以连接网络或者检查浏览器的选项中安全设置。<a href= "http://www.mxdraw.com/MxDrawX52.msi" >http://www.mxdraw.com/MxDrawX52.msi 安载CAD控件</a></SPAN> </object> |
首先通过id得到两个控件,新建一个COM组件对象,设置打印的位置等常规设置,具体实现js代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
function BatchPrintDialog() { var ocx1 = document.getElementById( "MxDrawXCtrl1" ); var ocx2 = document.getElementById( "MxDrawXCtrl2" ); var print = ocx1.NewComObject( "IMxDrawPrint" ); // 开始打印. print.BeginNestedPrint(); //iFlag = 0表示页边距,iFlag = 1表示打印区域矩形框位置 print.Flag = 1; // 打印区位置(10,10,200,100),坐标系统是,X从左到右,Y从上到下. //打印的页边距的左边距离 print.dLeftPageMargin = 10; //打印的页边距的上边距离 print.dTopPageMargin = 10; //打印的页边距的右边距离 print.dRightPageMargin = 200; //打印的页边距的下边距离 print.dBottomPageMargin = 100; // 把屏幕显示内容进行的打印,打印第一个控件。 ocx1.MakeCurrentOcx(); print.PrintScreen(); ocx2.MakeCurrentOcx(); // 打印区位置(10,110,200,210),坐标系统是,X从左到右,Y从上到下. //打印的页边距的上边距离 print.dTopPageMargin = 110; //打印的页边距的下边距离 print.dBottomPageMargin = 210; // 把屏幕显示内容进行的打印,打印第二个控件。 print.PrintScreen(); //结束嵌套打印 print.EndNestedPrint(); } |
来源:https://www.cnblogs.com/yzy0224/p/10966479.html