related sites: <FREE Help> <ASP> <Asp.net> <worldwide> feedback: <lovethat> <hatethat> <thanks> <credits> <contact us>
Serving 468 x 60 Banner Ads <Next>
Making multi-page Book Printouts
We had to devise a tool to generate one printout from an entire site. Our first section we attempted this on is the /learn section. First we made a form to allow some specs:
<Test Script Below>
<html> <head> <title>ASP QuickLessons Print Setup</title> </head> <body bgcolor="#FFFFFF"> <form action="printoutmake.asp" method="get"> <table border="0" width="100%"> <tr> <td width="33%"><font face="Arial"><strong>ASP Quick Lessons</strong></font></td> <td width="33%"><font face="Arial"><strong>by Charles Carroll</strong></font></td> <td width="34%"></td> </tr> <tr> <td width="33%"><font face="Arial">Start Page</font></td> <td width="33%"><font face="Arial"><input type="text" name="Start" size="7" value="1"> <strong><font color="#FF0000"><small>0=all pages</small></font></strong></font></td> <td width="34%"></td> </tr> <tr> <td width="33%"><font face="Arial">End Page</font></td> <td width="33%"><font face="Arial"><input type="text" name="End" size="7" value="0"> <strong><font color="#FF0000"><small>0=all pages</small></font></strong></font></td> <td width="34%"></td> </tr> <tr> <td width="33%"><font face="Arial">Print Direction</font></td> <td width="33%"><small><font face="Arial"><input type="radio" value="backwards" name="PrintDirection" checked>Backwards <input type="radio" name="PrintDirection" value="Forwards" checked>Forwards</font></small></td> <td width="34%"></td> </tr> <tr> <td width="33%"></td> <td width="33%"><font face="Arial"><small><input type="radio" value="print" checked name="PrintType">Printing <input type="radio" name="PrintType" value="offlineviewing">Offline Viewing</small></font></td> <td width="34%"></td> </tr> <tr> <td width="33%"><font face="Arial">Password*</font></td> <td width="33%"><font face="Arial"><input type="text" name="Password" size="25"></font></td> <td width="34%"></td> </tr> <tr> <td width="33%"></td> <td width="33%"><font face="Arial"><small>* Password only required to print more than 20 pages because server script places heavy load on server.</small></font></td> <td width="34%"></td> </tr> <tr> <td width="33%"></td> <td width="33%"><font face="Arial"><input type="submit" value="PrepareDocument" name="PrepareDocument"></font></td> <td width="34%"></td> </tr> </table> </form> </body> </html>
Then we came up with the code to respond to that form:
<% response.buffer=true server.scripttimeout=1080 Response.Expires = 0 Response.ExpiresAbsolute = Now() - 1 Response.AddHeader "cache-control", "private" Response.AddHeader "pragma", "no-cache" %> <html><head> <title>Entire Tutorial</title> <STYLE>.classPageBreak { page-break-after: always }</STYLE> </head> <body> <% 'call TOCIncludes("learn.txt") Call FileToString("learn.toc") %> </body> </html> <% SUB FileToString(tocname) Dim TL 'NextLink object Dim maxi 'Count variable Dim counter,maxcount 'Loop control Dim desc 'Description of link dim tocitem, urlitem dim prstatus,st,en Set TL = Server.CreateObject ("MSWC.NextLink") maxcount= cint(TL.GetListCount(tocname)) pagebreak="<P CLASS=""classPageBreak""><BR></P>" direction=lcase(mid(request("printdirection"),1,1)) prtype=lcase(mid(request("printtype"),1,1)) If prtype="p" then printflag="?printstatus=y" else printflag="" end if If direction="b" then st=request("start") en=request("end") direction=-1 else st=request("end") en=request("start") direction=1 end if if st>0 then ' do nothing else st=2 end if if en>0 then ' do nothing else en=maxcount end if IF lcase(request("password"))<>"mothra" and en-st>20 then response.redirect "printoutsetup.asp" END IF ' Ensure Cover Page and TOC is included Set HttpObj = Server.CreateObject("AspHTTP.Conn") ' tocitem="cover.asp" ' URLitem="http://www.activeserverpages.com/learn/" & tocitem & printflag ' HttpObj.Url = URLitem ' response.write HttpObj.GetURL & vbcrlf & pagebreak & vbcrlf ' tocitem="index.asp" ' URLitem="http://www.activeserverpages.com/learn/" & tocitem & printflag ' HttpObj.Url = URLitem ' response.write HttpObj.GetURL & vbcrlf & pagebreak & vbcrlf ' SET HTTPobj = nothing ' Done with Cover Pages and TOC for counter=en to st step direction IF response.isclientconnected=true THEN Set HttpObj = Server.CreateObject("AspHTTP.Conn") tocitem=TL.GetNthURL(tocname,counter) URLitem="http://www.activeserverpages.com/learn/" & tocitem & printflag HttpObj.Url = URLitem response.write HttpObj.GetURL & vbcrlf & pagebreak & vbcrlf SET HTTPobj = nothing END IF IF counter mod 40 = 0 THEN response.flush END IF next session("printview")=prstatus set TL=nothing END SUB SUB TOCIncludes(tocname) Dim TL 'NextLink object Dim maxi 'Count variable Dim counter,maxcount 'Loop control Dim desc 'Description of link dim tocitem Set TL = Server.CreateObject ("MSWC.NextLink") maxcount= cint(TL.GetListCount(tocname)) for counter=maxcount to 1 step -1 response.write "<!--#include virtual=""/learn/" response.write TL.GetNthURL(tocname,counter) & """-->" & vbcrlf next set TL=nothing %> <%end sub%>