Web page printing problems, print settings, print preview, print pages, vertical, horizontal, and page margins

Source: Internet
Author: User
Tags mdb database

1. Control the margin of "vertical", horizontal ", and" page"

(1)

<Object ID = "Factory" style = "display: none" viewastext classid = "CLSID: 1663ed61-23eb-11d2-b92f-008048fdd814"

Codebase = "http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"> </Object>

<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 = "javascriptrintit ()">

<Input type = button name = button_setup value = "print page settings"

Onclick = "javascriptrintsetup ();">

<Input type = button name = button_show value = "print preview"

Onclick = "javascriptrintpreview ();">

<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.doc ument. Close ();

Pwin. Print ();

}

</SCRIPT>

5. 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>


 

This is to call word to print

Add the following code between
<Object classid = CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2 Height = 0 id = WB width = 0> </Object>

<Script language = JavaScript>

Function doprintsetup (){

WB. execwb (8, 1)

}

Function doprintpreview (){

WB. execwb (7,1)

}

</SCRIPT>

In <body>, call:

<Input type = button name = button1 value = "Print Settings" onclick = "Return doprintsetup ()">

<Input type = button name = button2 value = "print preview" onclick = "Return doprintpreview ()">

<Input type = button name = button3 value = "print this page" onclick = "javascriptrint ()">

6. Set the part that you do not want to print

<Style>

@ Media Print {

. Xx {display: None}

}

</Style>

<Table width = "600" class = "XX" border = "0" cellspacing = "0" cellpadding = "0">

<Tr>

<TD Height = "60" align = "center"> tables you do not want to print </TD>

</Tr>

</Table>

7. Use Word to print web pages on the client

In the past, ASP also encountered the problem of printing in the browser, especially some applications in the LAN. The previous implementation defined a printing start mark and an ending mark, then, call window. the print () method also involves the printing problem when frame is used. The msdn document provides a detailed description of these issues. However, it is difficult to control them, moreover, it is difficult to implement precise control over printing. Many of my friends have also encountered this problem. I recently read an article about the implementation of Web-based printing (csdn ), I made some modifications and posted them for your reference. I hope they will help you.

You can call the word of the client to print it. The client must install word.

The method is as follows:

<%

Response. contenttype = "application/MSWord"

Response. addheader "content-disposition", "inline; filenameappsreport.doc"

%>

When the same content is added to ASP, the client automatically calls word to open the current document, but do not forget to set the property of response. buffer to false.

8. Example of the crystal solution for printing reports in the Web Environment

<% @ Language = "VBScript" %>

<%

'========================================

'Generate a report directly from ADO recordset

'========================================

'

'Concept:

'

'The application is designed to demonstrate how to generate a report from ADO recordset. We first establish the ADO connection and

'Recordset object, and then generate a record set from the database using SQL statements. Then we create a crystal

'Reports object, and point this object to ADO recordset. Finally, we set Crystal Reports

'Smart viewer sends the report to the client.

'Step 1: Create An ADO connection and recordset

'An ADO database connection is accessed through an existing ODBC Data Source (DSN) from an application such as ASP.

'Data connection. To achieve the purpose of this example, we will use

'Connect to the ACCESS database Xtreme. mdb system DSN

'Create an ADO database connection:

Set oconn = server. Createobject ("ADODB. Connection ")

'Create an ADO connection called "oconn" here. We will use this ADO connection object to connect to the DSN

'To use ADO connection, you must first open it:

Oconn. Open ("Xtreme Sample Database ")

'Open the ODBC Data source. This data source points to the ACCESS database Xtreme. MDB.

'Now we must create a recordset object:

Set SESSION ("ors") = server. Createobject ("ADODB. recordset ")

'The above we created a session ("ors"). This session stores A recordset object.

'Contains the data returned by SQL statements.

'Define and generate recordset:

Session ("ors"). activeconnection = oconn

'Define the connection object to be used by this recordset.

Session ("ors"). Open "select [product ID], [product name] from product"

'Use an SQL statement to retrieve two fields from the "product" table of the Xtreme. mdb database

'================================================ ========================================================== ====

'Create a Crystal Reports object

'================================================ ========================================================== ====

'You may have noticed that the Crystal Reports object is set as session, because it is called

To enable rptserver. asp to easily access the Crystal Report object,

'Let's set these objects to sessions. In this way, any ASP page runs in this session and can directly access these objects.

Reportname = "adorecordset. rpt"

'Create a string variable to point to the crystal report file (. rpt file ).

'Change to your crystal report file name.

'Create Application Object

If not isobject (Session ("oapp") then

Set SESSION ("oapp") = server. Createobject ("crystalruntime. application ")

End if

'This "If/end if" structure is used to create only one Crystal Reports application object o for each session

'Create Application Object-session ("oapp"), and set the crystal report design component

'Automation server (craxdrt. dll) is loaded into the memory.

'

'The session variables are created to use them in the ASP session process. This reduces the number of craxdrt. dll

'System overhead for loading and detaching. Once an application object is created in a session, we do not need

'Recreate the object to run more reports.

'Create a report object

'

'The report object is created by the openreport method of the application.

Path = request. servervariables ("path_translated ")

While (right (path, 1) <> "\" and Len (PATH) <> 0)

Ilen = Len (PATH)-1

Path = left (path, ilen)

Wend

Response. Write path

The 'while/wend' loop is used to convert the current file from the virtual path (eg: http: // domain/DIR) to the Crystal

'Report file physical path (eg: C :\)

'Open the report (clear any previous objects first)

If isobject (Session ("orpt") then

Set SESSION ("orpt") = nothing

End if

On Error resume next

Set SESSION ("orpt") = SESSION ("oapp"). openreport (Path & reportname, 1)

'Here, the "path" and "reportname" variables are used to calculate the physical path of the crystal report file and open it.

If err. Number <> 0 then

Response. Write "error occurred creating report object:" & err. Description

Set SESSION ("orpt") = nothing

Set SESSION ("oapp") = nothing

Session. Abandon

Response. End

End if

'This on erro resume next block checks any errors that occur when a report object is created. We are explicitly capturing any

'Error if the view exceeds the maximum number of concurrent users specified by the license agreement.

'Note: we do not just create a report object once. This is because with ASP session, you can process more than one report.

'Rptserver. asp will only process a report object called SESSION ("orpt. Therefore, if you want to process multiple reports

Create a new session ("orpt") object.

Session ("orpt"). moreprintengineerrormessages = false

Session ("orpt"). enableparameterprompting = false

'The error reporting mechanism is not allowed here, including the crystal report design Component Automation server (craxdrt. dll)

'Built-in error reporting for two reasons:

'1. The printing engine is executed on the Web server, so any error information will be displayed on the server. If an error is reported on the server,

'Print engine will stop running and your application will be "suspended"

'2. rptserver. asp already has some error processing logic in it, which can capture any non-fatal error and display it on the client.

'

'** Important **: even if the server engine error handling is disabled, the fatal error will still be captured on the Web server and

'The error prompt dialog box is displayed. Therefore, we recommend that you set

'"Allow service to interact with desktop" option. In this way, if your ASP application is dead, you will be able to see the error message.

'================================================ ========================================================== ========

'================================================ ========================================================== ========

'Now we must tell the report data in ADO recordset.

'Report is based on dynamic ADO recordset. We must establish a report based on our recordset.

'Then we will tell the report data in the ADO record set at runtime. Reports usually rely on database structure files

'(Adorecordset. TTX) is created. This. TTX file contains the recordset structure and does not contain actual data.

'A crystal report fully depends on the data structure of the report to be used, so your database structure file (TTX file) at runtime)

'Or it is very important to reflect the DSN of the data contained in the ADO recordset.

Session ("orpt"). discardsaveddata

Set database = SESSION ("orpt"). Database

'The database used to instantiate the report

Set tables = database. Tables

'Instantiate the table in the database object

Set Table1 = tables. Item (1)

'Instantiate the first table. In this instance, this table object directs to the adorecordset. TTX file.

Table1.setprivatedata 3, Session ("ors ")

'"Setprivatedata" tells the report that the current data source is recordset, and the data to be displayed in the report is included in the Session ("ors ").

'If your report contains a subreport, different recordsets will be provided to point to the data of the subreport.

'

'================================================ ========================================================== =====

'Get record again and create "page on demand" engine object

'================================================ ========================================================== =====

On Error resume next

Session ("orpt"). readrecords

If err. Number <> 0 then

Response. Write "error occurred reading records:" & err. Description

Set SESSION ("orpt") = nothing

Set SESSION ("oapp") = nothing

Session. Abandon

Response. End

Else

If isobject (Session ("opageengine") then

Set SESSION ("opageengine") = nothing

End if

Set SESSION ("opageengine") = SESSION ("orpt"). pageengine

End if

'Instantiate Crystal Reports smart Viewer

'

'Use the Crystal Reports Automation server in the ASP environment. We use the same page to call it through the Crystal Web Report Server.

'"Smart viewers"

'There are four Crystal Reports smart viewers:

'

'1. ActiveX smart Viewer

'2. Java smart Viewer

'3. html frame smart Viewer

'4. html page smart Viewer

'

'The smart viewer you use will be compatible with the browser you use. For example, you will not use Java viewer If your browser

'Java applets is not supported. For this reason, in this demo, we have selected to define a viewer. You can decide through the Code

'Compatibility of the requested browser. In any case, this function inherits from the Crystal Reports Automation server,

'Exceeds the scope of this example.

'For simple reasons, we have chosen to implement this function through the functions included in the ASP server. You can choose different

The 'smartviewer *. asp file is sent to different browsers and simply replaced by the smart viewer ASP file you want.

'These options are: smartvieweractivex. asp, smartviewerjave. asp, smartviewerhtmlframe. asp,

'And smartviewerhtmlpage. asp. Note that when using these include files, you must place the corresponding. asp files in the same master

'Asp files are in the same virtual path.

'

'* Note * For smartviewerhtmlframe and smartviewerhtmlpage, you must have framepage. asp in the virtual path.

'File and toolbar. asp file

Viewer = request. Form ("Viewer ")

'Read the value of the used Viewer and put it in the variable "Viewer ".

If CSTR (viewer) = "ActiveX" then

%>

<! -- # Include file = "smartvieweractivex. asp" -->

<%

Elseif CSTR (viewer) = "Netscape plug-in" then

%>

<! -- # Include file = "activexpluginviewer. asp" -->

<%

Elseif CSTR (viewer) = "Java using browser JVM" then

%>

<! -- # Include file = "smartviewerjava. asp" -->

<%

Elseif CSTR (viewer) = "Java using Java Plug-in" then

%>

<! -- # Include file = "javapluginviewer. asp" -->

<%

Elseif CSTR (viewer) = "HTML frame" then

Response. Redirect ("htmstart. asp ")

Else

Response. Redirect ("rptserver. asp ")

End if

'The above if/then/else is designed to test the value of the "Viewer" variable. Based on this value, send the appropriate crystal smart Viewer

%>

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.