Javascript print (print page settings/print preview code)

Source: Internet
Author: User

Copy codeThe Code is as follows: <HTML> <HEAD> <TITLE> javascript printing-print page settings-print preview Code </TITLE>
<META http-equiv = Content-Type content = "text/html; charset = gb2312"/>
<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>
<DIV align = center>
<OBJECT id = wb height = 0 width = 0
Classid = CLSID: 8856F961-340A-11D0-A96B-00C04FD705A2 name = wb> </OBJECT>
<INPUT onclick = javascript: printit () type = button value = Print name = button_print/>
<INPUT onclick = javascript: printsetup (); type = button value = print page setting name = button_setup/>
<INPUT onclick = javascript: printpreview (); type = button value = print preview name = button_show/>
</DIV>
</BODY>
</HTML>

Javascript print Overview
(1)Copy codeThe Code is as follows: <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)Copy codeThe Code is as follows: <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 ();">

------------------------------------------------
Other usage of this component is as follows::
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 Copy codeThe Code is as follows: <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)Copy codeThe Code is as follows: <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" nclick = pagesetup_null ()> <input type = "button" value = "Restore page" nclick = pagesetup_default ()> <br/>
</P>
</BODY>
</HTML>

4. Floating frame Printing Copy codeThe Code is as follows: <SCRIPT. LANGUAGE = javascript>
Function button1_onclick (){
Var doc=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>

5. Use the FileSystem component to implement specific local printing in WEB Applications Copy codeThe Code is as follows: <script. Language = VBScript>
Function print_onclick // print the function
Dim label
Label = document. printinfo. label. value // obtain HTML page data
Set bjfs = CreateObject ("Scripting. FileSystemObject") // create an instance of the FileSystem Component Object
Set bjprinter = 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 bjprinter = nothing
Set bjfs = nothing // disable the FileSystem Component Object
End function
</Script>

Server scripts:Copy codeThe Code is as follows: <% .........
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:Copy codeThe Code is as follows: <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>

Related Article

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.