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 ".
Program code: <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>
When I add the code here to aspx, the page will be faulty.
How can this problem be solved. I want to print only one frame of multiple frame pages. How can I implement this? Don't understand
Program code: <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>
<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. Code of the paging Printing Program: <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?
IE File-> page settings-> the content in the header and footer is removed, and the print will not be available.
Program code: <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
Program code: <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
Program code: <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> Signature ---------------------------------------------------------------------------------------------
<Script language = "JavaScript">
Function printit (){
If (NS ){
Window. Print ();
} Else {
VaR webbrowser = '<Object ID = "webbrowser1" width = 0 Height = 0 classid = "CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2"> </Object> ';
Document. Body. insertadjacenthtml ('foreend', webbrowser );
Webbrowser1.execwb (7, 2); // use a 1 vs. A 2 for a prompting dialog box
Webbrowser1.outerhtml = "";
}
}
</SCRIPT>
<Script language = "JavaScript">
VaR NS = (navigator. appname = "Netscape ");
VaR version = parseint (navigator. appversion );
If (version> 3 ){
Document. Write ('<form> <input type = button value = "JavaScript" name = "print" onclick = "printit ()"> </form> ');
}
</SCRIPT>