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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP PDF Page - Quick and Dirty 1

Status
Not open for further replies.

SMerrill

Programmer
Jan 19, 2002
145
US
Crystal Developers:

Here is the code I ended up with after messing around with the PDF paradigm for about a week. I post it here to request for comments to improve it and make it more bullet-proof, so [machinegun] please give me both barrels!

My intent is to simply create a PDF and display it in front of the customer.

--Shaun Merrill[idea]
Seattle, WA

Code:
<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<html>
<body>
<%

reportname = &quot;crystal.rpt&quot; 'REPLACE WITH YOUR REPORT NAME
ExportFileName = Session.SessionID & &quot;.PDF&quot;
ExportDirectory = &quot;c:\inetpub\[URL unfurl="true"]wwwroot\Reports&quot;[/URL] 'BE SURE TO CREATE THIS DIRECTORY
ReportCacheVirtualDirectory = &quot;/Reports/&quot;

If Not IsObject ( session(&quot;oApp&quot;)) Then                              
  Set session(&quot;oApp&quot;) = Server.CreateObject(&quot;CrystalRuntime.Application.8.5&quot;)
End If                                                                

If IsObject ( session(&quot;oApp&quot;)) Then
  Path = Request.ServerVariables(&quot;PATH_TRANSLATED&quot;)                     
  While (Right(Path, 1) <> &quot;\&quot; And Len(Path) <> 0)                      
    iLen = Len(Path) - 1                                                  
    Path = Left(Path, iLen)                                               
  Wend                                                                  

  Set session(&quot;oRpt&quot;) = session(&quot;oApp&quot;).OpenReport(path & ReportName,1)                                                                   
  Set crystalExportOptions = Session(&quot;oRpt&quot;).ExportOptions

  crystalExportOptions.DiskFileName = ExportDirectory & &quot;\&quot; & ExportFileName
  crystalExportOptions.FormatType = cint(&quot;31&quot;) 'Adobe Acrobat
  crystalExportOptions.DestinationType = 1     'file=1

  Session(&quot;oRpt&quot;).Export False 'Create the PDF file

  On Error Resume Next                                                  
  session(&quot;oRpt&quot;).ReadRecords                                           
  If Err.Number <> 0 Then
    dim s                                               
    s = &quot;<p>An Error has occured on the server &quot;
    s = s & &quot;in attempting to access the following data source - &quot;
    s = s & session(&quot;pubs_ConnectionString&quot;) & &quot;</p>&quot;
    Response.Write(s)
  Else                                                                
    Set session(&quot;oPageEngine&quot;) = session(&quot;oRpt&quot;).PageEngine
    
    'Redirect the user to the PDF file              
    Response.Redirect(ReportCacheVirtualDirectory & ExportFileName)
  End If                                                                
End if
%>
</body>
</html>
 
One thing it doesn't do is clean out the Reports directory, which accumulates PDF files over time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top