SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to print from asp

    on my asp page i am showing list from my database now i want that page
    i. e. the list on my PAGE TO BE PRINTED WHEN I CLICK ON FILE--PRINT
    option. but i dont want the header & footer of that page.

    i used this in my asp page holi.asp where the list is.
    <A HREF="printholiday.asp?REF=holi.asp">
    View a Printer-Friendly Version of this Web Page!
    </A>

    Then in printholiday.asp page i write following block of code.

    but my problem is that on clicking on the hyperlink.
    i get directed to the printholiday page without header & footer
    but only the table title it is showing & not displaying the data.
    why?
    besides that i dont want that hyperlink without that is it possible to take the print clicking on file --> print option
    using IE.
    Pl. Reply so that i can come out of this .


    <%
    Const ForReading = 1

    Dim strReferrer, objFSO, objOpenFile, strLine
    strReferrer = Request.QueryString("REF")

    If Len(strReferrer) < 1 then
    strReferrer = Request.ServerVariables("HTTP_REFERER")

    If Len(strReferrer) < 1 then
    Response.Write "Egad! An Error occurred! We could not" & _
    " determine what page you wanted to view the source for..."
    Response.End
    Else

    strReferrer = Right(strReferrer,len(strReferrer)-7)
    strReferrer = Right(strReferrer,len(strReferrer) - _
    instr(1,strReferrer,"/")+1)
    End If

    End If




    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objOpenFile = objFSO.OpenTextFile(Server.MapPath(strReferrer), _
    ForReading)

    'Output each line of the file...
    Do Until objOpenFile.AtEndOfStream
    strLine = objOpenFile.ReadLine
    Response.Write strLine & vbCrLf
    Loop

    objOpenFile.Close
    Set objOpenFile = Nothing
    Set objFSO = Nothing
    %>

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your filesystemobject method won't work. It's writing the raw ASP to the browser without processing any of the commands.

    Your best bet is to look into using CSS styling to do this. You can specify media types for stylesheets ("print" for printer output, "screen" for normal display). A simple example:
    Code:
    <html>
    <head>
    <style type="text/css">
    @media print, screen {
    	body {
    		font: 10pt Arial;
    	}
    }
    @media print {
    	div#header {
    		display: none;
    	}
    	div#footer {
    		display: none;
    	}
    }
    </style>
    </head>
    <body>
    <div id="header">THIS IS THE HEADER</div>
    <div id="content">THIS IS THE CONTENT</div>
    <div id="footer">THIS IS THE FOOTER</div>
    </body>
    </html>

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The way I have done similar things in the past is via CSS declarations - i.e. you can define what gets shown on the screen and what gets printed by the browser. Here's an example of a CSS file I have used before - the key areas to look at are the @media declarations and the .printsection and .nonprintsection definitions.

    Code:
    @media screen {
    	#container {
    		width: 610px;
    		margin: 0;
    		margin-left: 156px;
    		font-family: Verdana, Arial, Helvetica, sans-serif;
    		font-size: 1em;
    		text-align: justify;
    	}
    
    	#logo {
    		position: absolute;
    		top: 115px;
    		left: 5px;
    		border: 0;
    		margin: 0;
    		padding: 0;
    		font-family: Verdana, Arial, Helvetica, sans-serif;
    		font-size: 18px;
    		color: #fff;
    	}
    
    	div.printsection {
    		display: block;
    	}
    	div.nonprintsection {
    		display: block;
    	}
    
    	td,p {
    		font-size: 0.9em;
    	}
    
    	li {
    		font-size: 0.9em;
    	}
    
    	td.errormsg {
    		color: #d00;
    		font-weight: bold;
    	}
    
    	.tablehead:a:link {
    		color: #fff;
    		font-weight: bold;
    		text-decoration: underline;
    	}
    	.tablehead:a:visited {
    		color: #fff;
    		font-weight: bold;
    		text-decoration: underline;
    	}
    	.tablehead:a:hover {
    		color: #f00;
    		font-weight: bold;
    		text-decoration: underline;
    	}
    	.tablehead:a:active {
    		color: #f00;
    		font-weight: bold;
    		text-decoration: underline;
    	}
    }
    
    @media print {
    	#container {
    		display: block;
    	}
    	#logo {
    		display: none;
    	}
    
    	div.printsection {
    		display: inline;
    	}
    
    	div.nonprintsection {
    		display: none;
    	}
    }
    Anything to be NOT printed should be contained within a DIV with id="nonprintsection".

    Edit:

    Jim got in while I was typing!
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Muahahaha.

    I would make that a div with class="nonprintsection"

    Otherwise you could have multiple divs with the same id.

    And that's naughty.

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I know - but that example was done a few years ago when I was first getting used to CSS.
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •