Batch printing of smsx.cab printing

The smsx.cab plug-in relies on ActiveX controls for printing, so the disadvantage is obvious: the page must allow to run ActiveX controls, and ActiveX controls are only supported by IE, so the limitations are very strong.

 

Basic structure of the page:

<div  id="floatDiv" align="right">
	<input style="color: #fff; font-size: 16px" onclick="printTures();" type="button" value="打印"/>
	<input style="color: #fff; font-size: 16px" onclick="printpage();" type="button" value="打印预览"/>
	<input style="color: #fff; font-size: 16px" onclick="pageReSet();" type="button" value="页面设置"/>
</div>
<div id="page"></div>

JS implementation:

// This event is fired when the "Print" button is hit
function printTures(){
	$("body").append("<OBJECT id=\"factory\" codeBase=\"redist/smsx.cab#Version=6,3,434,26\" height=\"0\" width=\"0\" classid=\"clsid:1663ed61-23eb-11d2-b92f-008048fdd814\" viewastext></OBJECT>");
	//Cancel the floating of the print area
	var printdiv = document.getElementById("page");
	printdiv.style.overflow="";
	
	printBase();//Make print settings
	
	//Hide the print button and print preview button
	document.getElementById("floatDiv").style.display = "none";// 隐藏按钮
	
	//Print: no confirmation print, if true, you need to confirm before printing
	factory.printing.Print(false);
	
	// print complete return item list
	$("#factory").remove();
}

// This event is fired when the "Print Preview" button is hit
function printpage(){
	$("body").append("<OBJECT id=\"factory\" codeBase=\"redist/smsx.cab#Version=6,3,434,26\" height=\"0\" width=\"0\" classid=\"clsid:1663ed61-23eb-11d2-b92f-008048fdd814\" viewastext></OBJECT>");
	//Cancel the floating of the print area
	var printdiv = document.getElementById("page");
	printdiv.style.overflow="";
	printBase();//Make print settings
	
	//Hide the print button and print preview button
	document.getElementById("floatDiv").style.display = "none";// 隐藏按钮
	// make a preview
	factory.printing.Preview();
	// print complete return item list
	printdiv.style.overflow="auto";
	//Hide the print button and print preview button
	document.getElementById("floatDiv").style.display = "block";// 隐藏按钮
	$("#factory").remove();
}

/**page settings*/
function pageReSet(){
	printBase ();
	factory.printing.PageSetup();
}

// used to set printing parameters
function printBase () {
	factory.printing.header = ""; // header
	factory.printing.footer = ""; // footer
	factory.printing.portrait = true; // true is vertical printing, false is horizontal printing
	factory.printing.leftMargin = 19.05;
	factory.printing.topMargin = 0;
	factory.printing.rightMargin = 0;
	factory.printing.bottomMargin = 0;
}

Note: There must be corresponding files in the codeBase=\"redist/smsx.cab#Version=6,3,434,26\" directory in the <Object> tag

 

The only feeling of using this plug-in is: it is very easy to adjust, but it is very troublesome to adjust. Once there is a problem, it is also troublesome to debug, because it is hooked to the browser and it also writes something to the operating system, which involves security issues. Conversely, if the settings of the browser or operating system are changed, it may also be blocked. Affected, so for it, "it's normal to use it in the morning and it can't be used in the afternoon".

 

Possible problems : If there are "Print" and "Print button" on the page at the same time, and both buttons are clicked (for example, if you click Print without refreshing, then click Print Preview), then when you click the second button May report an error: only one scriptx object can be used per browser windowThe solution can refer to this link: http://blog.csdn.net/zhao19861029/article/details/8283347

 

Like Jquery printing, let's talk about the advantages and disadvantages:

Disadvantages: poor compatibility, can only be used by IE; prone to problems and troublesome to debug;

Advantages: preview; after configuration, the print box will not pop up when printing, allowing you to select a printer, and you can also set headers, footers, and margins;

 

Finally, post a few helpful links for the smsx.cab plugin:

1. Experience with web printing controls: http://blog.csdn.net/zhao19861029/article/details/8283347

2. Use the smsx.cab component to implement printing and print preview functions under IE: http://blog.csdn.net/zhao19861029/article/details/8270194

3. The ultimate solution for ScriptX, smsx print control installation: http://blog.csdn.net/yjlwl1213/article/details/3929848

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326467517&siteId=291194637