Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing html pages

Status
Not open for further replies.

transparent

Programmer
Sep 15, 2001
333
GB
I have written a script (with a little help) which parses html documents for particular tags ie <!--print--> <!--/print--> in order to generate printer friendly versions of static html files. The problem is that if the script is not in the same directory as the calling html page (a print icon on the html page links to the script) paths to images are incorrect. Does anybody have any ideas how to remedy this?

Here is the code:


<%

' ****************************************************************
' V 1.0 Created by Richard Walsh (with help from tek-tips) June 2002
' Generate printable pages from html files.
' ****************************************************************

'*********************************************************************************
' Define and initialise variables
'*********************************************************************************
dim str_referer
dim str_referer_path
dim str_local_addr
dim str_OpenTag
dim str_CloseTag
dim int_OpenTag_Pos
dim int_CloseTag_Pos
dim int_ForReading
dim obj_FSO
dim obj_OpenFile
dim str_Text

'*********************************************************************************
' Determine abosulte path of refered page
'*********************************************************************************
str_referer = Request.ServerVariables(&quot;HTTP_REFERER&quot;)

str_Local_Addr = InStr(str_referer, Request.ServerVariables(&quot;LOCAL_ADDR&quot;)) + len(Request.ServerVariables(&quot;LOCAL_ADDR&quot;))
str_referer_path = server.mappath(mid(str_referer,str_Local_Addr,len(str_referer)))
str_referer_path = replace(str_referer_path,&quot;%20&quot;,&quot; &quot;)


'*********************************************************************************
' Define search criteria for print Tags
'*********************************************************************************
int_ForReading = 1
str_OpenTag = &quot;<!--print-->&quot;
str_CloseTag = &quot;<!--/print-->&quot;
int_OpenTag_Pos = 1
int_CloseTag_Pos = 1

'*********************************************************************************
' Obtain data from file
'*********************************************************************************

Set obj_FSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set obj_OpenFile = obj_FSO.OpenTextFile(str_Referer_path, int_ForReading)

'Output each line of the file...
Do Until obj_OpenFile.AtEndOfStream
str_Text = str_Text & obj_OpenFile.ReadLine
Loop


While (InStr(int_OpenTag_Pos, str_Text, str_OpenTag, 1) + Len(str_OpenTag) >= int_OpenTag_Pos) and (InStr(int_OpenTag_Pos, str_Text, str_OpenTag, 1) <> 0)
int_OpenTag_Pos = InStr(int_CloseTag_Pos, str_Text, str_OpenTag, 1) + Len(str_OpenTag)
If int_OpenTag_Pos Then
int_CloseTag_Pos = InStr(int_OpenTag_Pos, str_Text, str_CloseTag, 1)
str_printText = str_printText & (Mid( str_Text, int_OpenTag_Pos, int_CloseTag_Pos - int_OpenTag_Pos))
int_CloseTag_Pos = int_OpenTag_Pos
End If
Wend


obj_OpenFile.Close
Set obj_OpenFile = Nothing
Set obj_FSO = Nothing
%>

<html>
<head>
</head>
<body onload=&quot;javascript:window.print();&quot;>

<table align=&quot;center&quot;>
<tr><td align=&quot;center&quot;> <a href=&quot;<%=str_referer%>&quot;>Return to Site</a> </td></tr>
<tr><td>
<%=str_printText%>
</td></tr>
<tr><td align=&quot;center&quot;> <a href=&quot;<%=str_referer%>&quot;>Return to Site</a> </td></tr>
</table>

</body>
</html>


Cheers

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top