"JS" through the JS implementation of the supermarket ticket printing function--activex control

Source: Internet
Author: User
Tags ticket

    • In response to customer demand = =, to the web-side to achieve the function of printing small tickets
    • First, a printed small ticket (the total is obviously wrong, because there is the ability to modify the order, please ignore)

  

    • What is the way to achieve it: I think there are three kinds of it

1. Using a third-party browser control (this seems more convenient, my teacher also recommended me) to recommend a LODOP print control

2. Use CSS to write the template, and then directly with the page printing method (it should be so)

(The above two have not tried, these two days to try again)

3. Use Microsoft's own ActiveX control (ActiveX controls can implement calls to local files and other operations (previously tried to call CMD, implementation of Shutdown-s-T, on the Web control computer timer shutdown))

Of course, the disadvantage of this approach is also obvious: limited operating system-because it is Microsoft's things can only be under Windows, browser-because ActiveX can only be in IE browser. So the limitations are relatively large

    • Implementation process:

1. Edit "Word Small ticket template", to use the word "bookmark" this tool (through the "bookmark" positioning, JS can manipulate word in "bookmarks" the location specified by the changes, write content)

2. Open, assign, print to the Word template in JS

    • One, edit "word Small ticket template"

1. Take word2007 for example, first arrange the approximate style

      

2. Mark positioning with "bookmarks"

Select the text area you want to bookmark-click "Bookmark"-fill in the book signature-click "Add"-"locate" to see the location of this bookmark

    • Second, JS

Directly on the source code bar:

<type= "button"  value= "Toprinter"  onclick= " Viewtoword (); " />  
1 functionViewtoword () {2         //Current Time3         varTime ;4         varToday =NewDate ();5Time =today.tolocalestring ();6         7         Try {  8             //Create a ActiveXObject object9Wdapp =NewActiveXObject ("Word.Application"); Ten         }   One         Catch(e) { AConsole.log ("Unable to invoke Office Object! ", E) -Wdapp =NULL;  -             return;  the         } -Wdapp. Documents.Open ("F:\\printertemplate1.doc");//Open a local (client) Word template -Wddoc =Wdapp.  ActiveDocument;  -Wddoc. Bookmarks ("Ordernum"). Range.Text = "201509080959" + "\ n"; +Wddoc. Bookmarks ("Ordername"). Range.Text = "Zheng bin" + "\ n";  -Wddoc. Bookmarks ("OrderAddress"). Range.Text = "Www.cnblogs.com/zhengbin" + "\ n"; +Wddoc. Bookmarks ("Orderphonenum"). Range.Text = "qq:1746788394" + "\ n"; AWddoc. Bookmarks ("Orderdaocantime"). Range.Text = "10:00-11:00" + "\ n"; atWddoc. Bookmarks ("Ordertime"). Range.Text = "09-08 10:15"; -         //Add a table -         varmyTable = Wddoc. Tables.add (Wddoc. Bookmarks ("Ordercart"). range,3,3);//(Assignment area, number of rows, number of columns) -         //Hide Border -         varTable=wdapp. Activedocument.tables (1); -Table. Borders (-1). Linestyle=0; inTable. Borders (-2). Linestyle=0; -Table. Borders (-3). Linestyle=0; toTable. Borders (-4). Linestyle=0; +Table. Borders (-5). Linestyle=0; -Table. Borders (-6). Linestyle=0; the          for(i=1;i<=3;i++) {//Line *             //first column $              with(Mytable.cell (i,1). Range) {Panax NotoginsengFont. Size = 8;//Adjust font size -InsertAfter ("blog Park" +i);//What's inserted the             } +             //second column A              with(Mytable.cell (i,2). Range) { theFont. Size = 8; + InsertAfter (i); -Paragraphformat.alignment=1;//table Content alignment: 0-Left justified 1-centered 2-right justified $             } $             //third column -              with(Mytable.cell (i,3). Range) { -Font. Size = 8; theInsertAfter ("Priceless"); -paragraphformat.alignment=2;Wuyi             } the         } -Wddoc.saveas ("F:\\printertemp_cnblogs.doc");//Save temporary file word WuWddoc. Bookmarks ("Totalprice"). Range.Text = "Priceless" + "\ n"; -Wddoc. Bookmarks ("Time"). Range.Text =Time ; About         //Wdapp. ActiveDocument.ActiveWindow.View.Type = 1; $Wdapp.visible =false;//whether Word templates are visible -Wdapp. Application.printout ();//Call the automatic printing feature - wdapp.quit (); -Wdapp =NULL;  A}

At last:

    

    • Attention:

The first thing to do is to adjust the Internet options for IE browser-the custom level (under "ActiveX Controls and plugins" on the right, which can be enabled)

    

"Printer offline work" is generally USB is not plugged in, switch the socket, restart the printer can

    • Thank the following bloggers for their wonderful blog posts:

http://kuangbaoxu.iteye.com/blog/193311

http://baser.blog.51cto.com/4153192/844742

http://xiaosuncunzhang.blog.51cto.com/317407/584844

http://blog.csdn.net/weizengxun/article/details/6870880

Http://blog.sina.com.cn/s/blog_692d0a650100klr4.html

"JS" through the JS implementation of the supermarket ticket printing function--activex control

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.