best solution for web printing

Pain points of web printing

There are many solutions for winform printing, and the implementation is relatively easy, and the effect is also very dazzling; but now more and more systems are web systems, even mobile terminals. There are also very web printing solutions on the Internet, but there are many various problems, such as js compatibility, stability, etc., which have been entangled with many programmers, or web printing requires browsers to install ActiveX components, and ActiveX installation is not easy to succeed And so on. Plug-ins such as Lodop are still charged.

new solution

After analyzing various solutions, and sorting out the printing requirements of the web in heavy business scenarios (such as direct printing, direct printing without preview, and printing in specific formats), an optimal WEB printing solution for the production process is determined, and pure JS is submitted through post Data to the scheme of the print server.

  1. js can be more general without the language environment, no matter you are java, php, or even just a front end, there is no obstacle;
  2. Using the psot mode of the http protocol is simpler, the threshold is lower, and it can be done with a few lines of code; in fact, it is also possible to use the webSocket protocol, but it is not necessary when a long connection is not required.

Program web page implementation source code, source code

<html>
<head>
<title>宇田web打印demo</title>
<meta http-equiv="content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<script>
function webprint(){
    
     
	var key1=document.getElementById('key1').value;
	var key2=document.getElementById('key2').value;
	var params = {
    
    "key1":key1,"key2":key2}; 
	httpPost("http://127.0.0.1:6555",params); 
}
function httpPost(URL,PARAMS) {
    
     
	var temp = document.createElement("form"); 
	temp.action = URL; 
	temp.method = "post"; 
	temp.style.display = "none"; 
	for (var x in PARAMS) {
    
     
		var opt = document.createElement("textarea"); 
		opt.name = x; 
		opt.value = PARAMS[x]; 
		temp.appendChild(opt); 
		} 
		document.body.appendChild(temp); 
		temp.submit(); 
		return temp; 
	}
</script>
宇田web打印demo<br>
webprint demo
<input  style="width:160px" id="key1">
<input style="width:160px" id="key2" >
<input type="button" id="button" value="打印" onclick="webprint()" />
</body>
</html>

Print server demo and principle

Print server demo download
The print server only needs to listen to the port 6555 in the above code, and then parse out the printing parameters, which can be as convenient and flexible as the desktop software and can be customized for printing

insert image description here

Guess you like

Origin blog.csdn.net/zyqytsoft/article/details/83905226