Printer for Web Printing

Source: Internet
Author: User

Some time ago, I developed a Web express order Printing program for a friend. The program itself is very simple, with thousands of lines of code. I can do it over the weekend, because it is too simple, I only call it a program, not a system. However, after using it, my friend raised a pertinent requirement that the express Waybill was printed by a dot matrix printer, while the document was usually A4 paper, which was printed by a laser printer, I set their default printer as a dot matrix printer, so that although the express order can be printed directly (no print preview is required), but when they print documents, I am used to printing without selecting a printer. In this way, I often send the documents to be printed to the dot matrix printer, which wastes a lot of express tickets. I found through investigation that the average company now has two types of printers, one is a dot matrix printer, used to print various documents and invoices, and the other is a laser inkjet printer used to print documents, under normal circumstances, the document printer is set as the default printer.

I think as a programmer, no matter the size, simplicity, and complexity of the system, a good user experience is our design goal. We do programs and systems, in itself, to reduce user work, rather than making work more complex by using the programs and systems we develop. In terms of program operations, users can select less than once, so that users can do less than once, so that users can do less than once, so that users should do less error.

Under the guidance of this kind of thinking, I should keep improving on this little thing. This Web Print control is designed by myself. I just want to add the designated printer function on the basis of the original, so that users do not have to select the printer. After several hours of hard work, I can finally specify a printer. However, the name of the printer is hard to write in the program, and I find it inconvenient, especially for network printers, it is inconvenient to change "\" to "\". The name of the printer is generally long and there are spaces in the middle. It is easy to lose the wrong name. If it is wrong, the specified printer is invalid. I just want to do the right thing. I just need to capture the local printer list in the control and use it as a drop-down box for the user to select. Then I save the selected result, in this way, there will be no errors and flexibility. If your printer is reinstalled or moved to another computer, you just have to select it and you don't need to change the program any more.

The sample code for specifying a printer in the control is as follows:

 

Sample Code of the specified printer in the control

Protected void BtnDepositPrint_Click (object sender, EventArgs e)
{
String FileValue, PrintValue, ParaName, ParaValue;

FileValue = FileToString (". \ Frp \ DepositAmt. fr3 ");
ParaName = "ShopName '~ Printdepositadd '~ Printpaperno '~ Title ";//'~ It is the separator of each parameter.
ParaValue = "test restaurant"
+ "'~ Note: This document is a credential for your customer's deposit and is stamped effectively. Please present it at check-out. The lost person is at your own risk. Please save it properly. When the check-out time is, the fee is charged for half-day before, and the price for all-day is calculated after. The deposit is valid for one month and expired. For valuables, please submit them to the front-end for storage. Thank you! "
+ "'~ ID: 4325011980639512"
+ "'~ Deposit ticket ";

SqlConnection ConPrintTest = new SqlConnection (ConfigurationManager. ConnectionStrings ["PrintTestConnectionString"]. ToString ());
ConPrintTest. Open ();
DataSet DsCashLog = new DataSet ();
SqlDataAdapter DaCashLog = new SqlDataAdapter ("Select top 1 CashNo, CashDate, CashAmt, PayName, GuestName, RoomNo, ItemRemark, CashUserName, Remark From CashLog", ConPrintTest );
DaCashLog. FillSchema (DsCashLog, SchemaType. Source, "CashLog ");
DaCashLog. Fill (DsCashLog, "CashLog ");

PrintValue = TableToXml (DsCashLog. Tables ["CashLog"]);

DsCashLog. Dispose ();
ConPrintTest. Close ();

String ScriptStr;

ScriptStr = "<script language = 'javascript '> window. onload = function () {try {var ObjPrintMange = new ActiveXObject ('webprint. webPrintUnit ');} catch (e) {if (confirm ('print control is not installed. Do you want to download it now? ') {Window. location = '. /PrintActivex.exe ';} return;} var OldVersion = ObjPrintMange. version; NewVerion = '5. 0 () '; if (OldVersion <NewVerion) {ObjPrintMange = null; alert ('print controls need to be upgraded. Download it first, Disable IE, and install the upgraded version. '); Window. location ='./PrintActivex.exe '; return ;}"
+ "ObjPrintMange. CheckReg ('Company name', '3b8e5b998a3125ee89983ea940bb2aee ');" // registration code
+ "ObjPrintMange. Printer = '\\\ 192.168.1.88 \ Epson LQ-300K ';"
+ "ObjPrintMange. PrintReport ('"
+ FileValue + "','"
+ ParaName + "','"
+ ParaValue + "','"
+ PrintValue + "','','','','','');"
+ "ObjPrintMange = null; window. location = './Default. aspx' ;}</script>"; // The window. location is switched to the new webpage.
ScriptStr = ScriptStr. Replace (System. Environment. NewLine, string. Empty );

Response. Write (ScriptStr );
}

 

The following is an example code to read the local printer list of the client in the control:

<Script language = 'javascript '>

Window. onload = function (){
Try {
Var ObjPrintMange = new ActiveXObject ('webprint. webprintunit ');
}
Catch (e ){
If (confirm ('print control not installed, download now? ')){
Window. location = './PrintActivex.exe ';
}
Return;
}

Var OldVersion = ObjPrintMange. Version; NewVerion = '5. 0 (2011-08-01 )';
If (OldVersion <NewVerion ){
ObjPrintMange = null;
Alert (the 'print control needs to be upgraded. Download it first, Disable IE, and install the upgraded version. ');
Window. location = './PrintActivex.exe ';
Return;
}

ObjPrintMange. CheckReg ('Company name', '3b8e5b998a3125ee89983ea940bb2aee ');
Var ObjCmbPrinterList = document. getElementById ('cmbprinterlist ');
Var strPrinterList = ObjPrintMange. PrinterList;
Var arrayPrinterList = strPrinterList. split (';');
ObjCmbPrinterList. innerHTML = '';
For (var I = 0; I <arrayPrinterList. length-1; I ++ ){
ObjCmbPrinterList [I] = new Option (arrayPrinterList [I], 0 );
}

ObjPrintMange = null;
}

</Script>

Specify a printer for Web printing. For the print preview mode, the system sets the specified printer as the preferred printer. For direct printing, the system directly assigns the print task to the specified printer. If it is null, the default printer is used. The specified printer must be installed on the client computer. Both the local printer and the network printer can be used. For the name of the network printer, change "\" to "\", for example: ObjPrintMange. printer = '\\\\ 192.168.1.88 \ Epson LQ-300K';, if the specified Printer does not exist, it is the default Printer.

The Web Print control I designed is currently available for individuals to apply for free registration. If you have any questions, please join the QQ group: 218392762 (all groups: 135506194 and 2: 150850837 are full, please join the three groups) or directly ask me: 12988672.

Reports preview and edit URL: http://www.xinyuerj.com/ASP/

Http://www.xinyuerj.com/ASP.NET/

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.