Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Export crystal report to PDF

artiarti Posts: 55Member
Can any one help me to write a code in asp to convert .rpt file to pdf.
I have written a code as mentioned below.
passing reportname and report query dynamically.

But it is creating o byte pdf file.






<%
Function fnblnExportReport(oRpt, strFormat, strpath, strfilename, strErrMsg)
On Error Resume Next
Dim CrExportOptions
Set CrExportOptions = oRpt.ExportOptions
With CrExportOptions
Select Case strFormat
Case "PDF" : .FormatType = 31
.PDFExportAllPages = True
.DestinationType = 1 'crEDTDiskFile
.DiskFileName = strpath & "" & strfilename & ".PDF"
.UseReportNumberFormat = False
.UseReportDateFormat = False

End Select
End With

oRpt.Export False
If Err.number <> 0 Then
strErrMsg=Err.number & " : " & Err.Description
Set oRpt = nothing

fnblnExportReport=False
Else
strErrMsg = ""
fnblnExportReport=True
End If
Set CrExportOptions = Nothing
End Function
%>
<%
if Request.QueryString("reload")<>"reload1" then
'Response.Write("valloadwin")
%>




<%else%>

<%End If
if pcmon<>"" and pcyear<>"" then
repdesc = " for the month "&pcmon&" and the year "&pcyear&""
end if
response.write("

"&rptname &""&repdesc&"

")
USRID=valdsndet(1)
PWD=valdsndet(2)
DSN=valdsndet(3)
'Response.Write " query = " &query

Set oConn = Server.CreateObject("ADODB.Connection")

oConn.ConnectionTimeout = 3600 '--------Added by Mamta 08-01-2007
oConn.CommandTimeout = 3600

if Len(USRID) <> 0 Then

oConn.Open "DSN="&DSN&";uid="&USRID&";pwd="&PWD
else
oConn.Open("DSN=GISICICI;uid=sa;pwd=;")
End If
'oConn.Open("DSN=GIS;uid=sa;pwd=;")

set session("oRs") = Server.CreateObject("ADODB.Recordset")
session("oRs").ActiveConnection = oConn

session("oRs").Open query

' CREATE THE APPLICATION OBJECT
If Not IsObject (session("oApp")) Then
Set session("oApp") = Server.CreateObject("CrystalRuntime.Application.10")
End If

Path = Request.ServerVariables("PATH_TRANSLATED")

While (Right(Path, 1) <> "" And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend
'OPEN THE REPORT (but destroy any previous one first)

If IsObject(session("oRpt")) then
Set session("oRpt") = nothing
End if

On error resume next

Set session("oRpt") = session("oApp").OpenReport(path & reportname, 1)

If Err.Number <> 0 Then
Response.Write "Error Occurred creating Report Object: " & Err.Description
Set Session("oRpt") = nothing
Set Session("oApp") = nothing
Session.Abandon
Response.End
End If

session("oRpt").MorePrintEngineErrorMessages = False
session("oRpt").EnableParameterPrompting = False

'A Crystal Report is completely dependant on the structure of the dataset the report
'will use. Therefor it is important that your database structure (ttx file) or DSN
'reflects EXACTLY the data that is contained in the ADO recordset at runtime.

'session("oRpt").DiscardSavedData
set Database = session("oRpt").Database
set Tables = Database.Tables
set Table1 = Tables.Item(1)
Table1.SetPrivateData 3, session("oRs")

' Retrieve the Records and Create the "Page on Demand" Engine Object

On Error Resume Next
If Err.Number <> 0 Then
Response.Write err.Description
Response.end
End if
session("oRpt").ReadRecords

If fnblnExportReport(session("oRpt"), "PDF",path,"ASD12", strErrMsg) = False Then
Set Session("oRpt") = nothing
Set Session("oApp") = nothing
Response.Write err.number & "
" & err.Description
Else
Response.write "Successfully exported"
End If

If Err.Number <> 0 Then
Response.Write "Error Occurred Reading Records1: " & Err.Description
Set Session("oRpt") = nothing
Set Session("oApp") = nothing
Session.Abandon
%>
<%
Response.End
Else
If IsObject(session("oPageEngine")) Then
set session("oPageEngine") = nothing
End If
set session("oPageEngine") = session("oRpt").PageEngine

End If
%>
<%
'CALL EXPORT REPORT FUNCTION
'
%>

<%

oConn.close
%>




<%


'==================================================================
'
' EXPORT THE REPORT
'
' - set the response header to the appropriate type
' - redirect to RDCrptserver10.asp
'
'Format Command Line ContentType
'MS Word RDCrptserver10.asp?cmd=export&export_fmt=crxf_wordw:0 application/msword
'Rich Text RDCrptserver10.asp?cmd=export&export_fmt=crxf_rtf:0 application/rtf
'ExcelDataOnly RDCrptserver10.asp?cmd=export&export_fmt=crxf_xls:10 application/vnd.ms-excel
'Excel RDCrptserver10.asp?cmd=export&export_fmt=crxf_xls:0 application/vnd.ms-excel
'CrystalReports RDCrptserver10.asp?cmd=export&export_fmt=u2fcr:0 application/x-rpt
'PDF RDCrptserver10.asp?cmd=export&export_fmt=crxf_pdf:0 application/pdf
'
'==================================================================
'Response.Clear
'Response.ContentType = "application/pdf"
'Response.Redirect "RDCrptserver10.asp?cmd=export&export_fmt=crxf_pdf:0"
%>


/*function setResult(sernm)
{
window.close();
}*/

Sign In or Register to comment.