ASP development essentials: Web Printing code Daquan this article mainly introduces how to use ASP to control various web printing effects, which can control vertical, horizontal, and page margins. 1. Control "vertical", "horizontal", and "Page margins ". (1)
|
<SCRIPT defer> Function setprintsettings (){ // -- Advanced features Factory. Printing. setmarginmeasure (2) // measure margins in inches Factory. setpagerange (false, 1, 3) // need pages from 1 to 3 Factory. Printing. Printer = "HP Deskjet 870c" Factory. Printing. Copies = 2 Factory. Printing. collate = true Factory. Printing. papersize = "A4" Factory. Printing. papersource = "manual feed" // -- Basic Features Factory. Printing. header = "this is meadco" Factory. Printing. footer = "advanced printing by scriptx" Factory. Printing. Portrait = false Factory. Printing. leftmargin = 1.0 Factory. Printing. topmargin = 1.0 Factory. Printing. rightmargin = 1.0 Factory. Printing. bottommargin = 1.0 } </SCRIPT> |
(2)
|
<Script language = "JavaScript"> Function printsetup (){ // Print page settings Wb.exe CWB (8, 1 ); } Function printpreview (){ // Print the Page Preview Wb.exe CWB (7,1 ); } Function printit () { If (confirm ('Are you sure you want to print? ')){ Wb.exe CWB (6, 6) } } </SCRIPT> </Head> <Body> |
|
<Object classid = "CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2" Height = 0 id = WB name = WB width = 0> </Object> <Input type = button name = button_print value = "print" Onclick = "javascript: printit ()"> <Input type = button name = button_setup value = "print page settings" Onclick = "javascript: printsetup ();"> <Input type = button name = button_show value = "print preview" Onclick = "javascript: printpreview ();"> <Input type = button name = button_fh value = "disabled" Onclick = "javascript: window. Close ();"> |
------------------------------------------------ There are other usage examples of this component: Webbrowser. execwb () Open Web. execwb () Close all existing IE Windows and open a new window Web. execwb () save Web Page Web. execwb (6, 1) Printing Web. execwb (7,1) print and preview Web. execwb (8, 1) Printing page settings Web. execwb () view page properties Web. execwb () seems to be undo, to be confirmed Select all web. execwb () Web. execwb (22, 1) Refresh Web. execwb () Close form no prompt 2. Paging Printing
|
<HTML> <Head> <Style> P {page-break-after: Always} </Style> </Head> <Body> <% While not Rs. EOF %> <P> <% = RS (0) %> </P> <% Rs. movenext %> <% Wend %> </Body> </Html> |
3. How to remove the path at the bottom of the page and the page number at the top of the page during ASP page printing? (1) The IE File-> page settings-> the content in the header and footer is removed, and the print is not displayed. (2)
|
<HTML> <Head> <Title> new document </title> <Meta name = "generator" content = "editplus"> <Meta name = "author" content = "YC"> <Script language = "VBScript"> |
|
Dim hkey_root, hkey_path, hkey_key Hkey_root = "HKEY_CURRENT_USER" Hkey_path = "/software/Microsoft/Internet Explorer/pagesetup" '// Set the page header and footer to be blank Function pagesetup_null () On Error resume next Set regwsh = Createobject ("wscript. Shell ") Hkey_key = "/Header" Regwsh. regwrite hkey_root + hkey_path + hkey_key ,"" Hkey_key = "/footer" Regwsh. regwrite hkey_root + hkey_path + hkey_key ,"" End Function '// Set the page header and footer to the default value. Function pagesetup_default () On Error resume next Set regwsh = Createobject ("wscript. Shell ") Hkey_key = "/Header" Regwsh. regwrite hkey_root + hkey_path + hkey_key, "& W & B page number, & P/& P" Hkey_key = "/footer" Regwsh. regwrite hkey_root + hkey_path + hkey_key, "& U & B & D" End Function </SCRIPT> </Head> <Body> <Br/> <Br/> <Br/> <Br/> <Br/> <Br/> <p align = center> <Input type = "button" value = "Clear page number" onclick = pagesetup_null ()> <input type = "button" value = "Restore page" onclick = pagesetup_default ()> <br/> </P> </Body> </Html> |
4. Floating frame Printing
|
<Script language = JavaScript> Function button1_onclick (){ VaR odoc=w.w.iframe1.doc ument; VaR r = odoc. Body. createTextRange (); VaR stxt=r.html text; Alert (stxt) VaR pwin = Window. Open ("", "print "); Pwin.doc ument. Write (stxt ); Pwin. Print (); } </SCRIPT> |
4. Use the filesystem component to implement specific local printing in Web Applications
|
<Script language = VBScript> Function print_onclick // print the Function Dim label Label = Document. printinfo. Label. Value // obtain HTML page data Set objfs = Createobject ("scripting. FileSystemObject") // create an instance of the filesystem Component Object Set objprinter = objfs. createtextfile ("LPT1:", true) // establish a connection with the printer Objprinter. writeline ("__________________________________") // output printed content Objprinter. writeline ("| ") Objprinter. writeline ("| the data you printed is:" & label & "| ") Objprinter. writeline ("| ") Objprinter. writeline ("| _________________________________ | ") Objprinter. Close // disconnect from the printer Set objprinter = nothing Set objfs = nothing // disable the filesystem Component Object End Function </SCRIPT> Server script: <% ......... Set conn = server. Createobject ("ADODB. Connection ") Conn. Open "DSN = Name; uid = xxxx; Pwd = xxxx ;" Set rs = server. Createobject ("ADODB. recordset ") Rs. Open ("select ......"), Conn, 1, 1 .......... %> // Interact with the database HTML page encoding: <HTML> ......... <Form ID = printinfo name = "printinfo"> <Input type = "button" value = "Print>" id = Print name = print> // call the print function <Input type = hidden id = text1 name = label value = <% = ......... %> // Save data sent from the server ......... </Html> |
|