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
please give me both barrels!
My intent is to simply create a PDF and display it in front of the customer.
--Shaun Merrill![[idea] [idea] [idea]](/data/assets/smilies/idea.gif)
Seattle, WA
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] [machinegun] [machinegun]](/data/assets/smilies/machinegun.gif)
My intent is to simply create a PDF and display it in front of the customer.
--Shaun Merrill
![[idea] [idea] [idea]](/data/assets/smilies/idea.gif)
Seattle, WA
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<body>
<%
reportname = "crystal.rpt" 'REPLACE WITH YOUR REPORT NAME
ExportFileName = Session.SessionID & ".PDF"
ExportDirectory = "c:\inetpub\[URL unfurl="true"]wwwroot\Reports"[/URL] 'BE SURE TO CREATE THIS DIRECTORY
ReportCacheVirtualDirectory = "/Reports/"
If Not IsObject ( session("oApp")) Then
Set session("oApp") = Server.CreateObject("CrystalRuntime.Application.8.5")
End If
If IsObject ( session("oApp")) Then
Path = Request.ServerVariables("PATH_TRANSLATED")
While (Right(Path, 1) <> "\" And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend
Set session("oRpt") = session("oApp").OpenReport(path & ReportName,1)
Set crystalExportOptions = Session("oRpt").ExportOptions
crystalExportOptions.DiskFileName = ExportDirectory & "\" & ExportFileName
crystalExportOptions.FormatType = cint("31") 'Adobe Acrobat
crystalExportOptions.DestinationType = 1 'file=1
Session("oRpt").Export False 'Create the PDF file
On Error Resume Next
session("oRpt").ReadRecords
If Err.Number <> 0 Then
dim s
s = "<p>An Error has occured on the server "
s = s & "in attempting to access the following data source - "
s = s & session("pubs_ConnectionString") & "</p>"
Response.Write(s)
Else
Set session("oPageEngine") = session("oRpt").PageEngine
'Redirect the user to the PDF file
Response.Redirect(ReportCacheVirtualDirectory & ExportFileName)
End If
End if
%>
</body>
</html>