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

.NET / BOE-XI (R2) SDK : View-On-Demand as PDF..? 1

Status
Not open for further replies.

MJRBIM

MIS
May 30, 2003
1,579
CA
.NET SDK
BOE-XI (R2)
___________

Within our developer's .NET application they are using the SDK to run the RPTs to the default Crystal Report Viewer based on the samples posted by BOBJ on the DIAMOND site.

This is fine for most reports, but one Report is a "Systems Dump" report that has 400+ pages and 15 sub-reports per page (don't even ask....) - this report takes a long time to render in the default Crystal Report Viewer and sometimes crashes the .NET application.

Does anyone have a method of rendering the on-demand RPTs directly to PDF within a .NET application...?

Could you please share that code with me and/or point me in the direction of the sample or knowledgebase you used for that solution...?

Thanks in advance.
 
I've done a lot of work in the SDK, but I'm not sure that can do what you're trying to do the way you've explained. To get the report to a PDF format, you would have to execute the report without showing the viewer, export it to PDF, and then view the resulting file. With 15 subreports per page, it's not going to run any faster this way. The problem is not the rendering, it's the generation of the subreports.

Do you have "page n of m" on the report? If so, take it off and just include the current page number. This will the report from having to generate ALL of the subreports prior to displaying the first page.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Hilfy :

Do you have any code samples for that "execute the report without showing the viewer, export it to PDF, and then view the resulting file" solution...?

If so, can I get a copy?

Thanks,
MJRBIM
 
MJRBIM,

Not that I can easily get my hands on right now. It's not something that I've done, but I've seen the code for executing reports on another forum. (I think at
-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
hello
This is what i have been using with the .net report engine version 9 thru 11.5. some of the methods can be updated to take advantage of version IX object model but this still works.

it depends on a TempReports directory on the server which is the location of the pdf file during processing.
Code:
Sub PrintCrystalReport
     Dim ErrorFound As Boolean = False
     Dim PathReport As String
     Dim crRepDoc As New ReportDocument
     Dim crSubRepDoc As New ReportDocument
     Dim crSections As Sections
     Dim crSection As Section
     Dim crRepObjs As ReportObjects
     Dim crRepObj As ReportObject
     Dim crSubRepObj As SubreportObject

     Dim crParamFieldDef As ParameterFieldDefinition
     Dim crParamFieldDefs As ParameterFieldDefinitions
     Dim crParamValues As New ParameterValues()
     Dim crParamDiscreteValue As New ParameterDiscreteValue()

     Dim crExportOptions As ExportOptions
     Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
     Dim crDatabase As Database
     Dim crTables As Tables
     Dim crTable As Table
     Dim crLogOnInfo As TableLogOnInfo
     Dim crConnInfo As New ConnectionInfo()
     Dim Temp As String
     Dim FName As String
    dim i
    dim j
    dim m
    Dim PathReportName As String
    dim TempReportPath As String
    Dim crReportDoc As ReportDocument
    Dim crDiskFileDestOptions As DiskFileDestinationOptions
    Dim SessionID As String
      
       CrystalErrorMessage = ""
       PathReport = CrystalReportPath & CrystalReportName
       crRepDoc = New ReportDocument()
       ReportingServerOnline = ISReportingServerOnline()

       If MyContext.Response.IsClientConnected = False then
         TerminateCrystalReport()
       End If

       Try
	     crRepDoc.Load(PathReport)
	     'Throw New OutOfLicenseException("testing out of license exception", EngineExceptionErrorID.OutOfLicense)
         Catch engEx As OutOfLicenseException
	     CrystalErrorMessage = "Currently all of the available Crystal Reports Licenses are in use. Please wait a moment and try again."
	     WriteToReportLog(Crystaleventid, CrystalReportName,"Error Creating Report", engEX.Message)
         Exit Sub
       Catch engEx As EngineException
	     CrystalErrorMessage = engEx.Message
	     WriteToReportLog(Crystaleventid, CrystalReportName,"Error Creating Report", engEX.Message)
	     Exit Sub
       End Try

       If MyContext.Response.IsClientConnected = False then
         TerminateCrystalReport()
       End If

       crDatabase = crRepDoc.Database
       crTables = crDatabase.Tables

       For Each crTable In crTables
      With crConnInfo
        If UseRptServer = True And ReportingServerOnline Then
          .ServerName = ConfigurationSettings.AppSettings("ReportServerName")
          .DatabaseName = ConfigurationSettings.AppSettings("ReportDatabaseName")
          .UserID = ConfigurationSettings.AppSettings("ReportUserID")
          .Password = ConfigurationSettings.AppSettings("ReportPassWord")
        Else
          .ServerName = ConfigurationSettings.AppSettings("OLEDBServerName")
          .DatabaseName = ConfigurationSettings.AppSettings("OLEDBDatabaseName")
          .UserID = ConfigurationSettings.AppSettings("OLEDBUserID")
          .Password = ConfigurationSettings.AppSettings("OLEDBPassWord")
        End If
      End With
      crLogOnInfo = crTable.LogOnInfo
      crLogOnInfo.ConnectionInfo = crConnInfo
      crTable.ApplyLogOnInfo(crLogOnInfo)

      ' Commented out 11/13/2003 - Because of Database name change causing CR to probe SP with nulls
      ' --------------------------------------------------------------------------------------------
      'If InStr(crTable.Location.ToString, ".") Then
      '  If UseRptServer = True Then
      '      crTable.Location = ConfigurationSettings.AppSettings("ReportDatabaseName") & ".dbo." & _
      '                          crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
      '  Else
      '      crTable.Location = ConfigurationSettings.AppSettings("OLEDBDatabaseName") & ".dbo." & _
      '                          crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
      '  End If
      'End If

      Next

       crSections = crRepDoc.ReportDefinition.Sections
       For Each crSection In crSections
         crRepObjs = crSection.ReportObjects
      For Each crRepObj In crRepObjs
           If crRepObj.Kind = ReportObjectKind.SubreportObject Then
       crSubRepObj = CType(crRepObj, SubreportObject)
             Try
               crSubRepDoc = crSubRepObj.OpenSubreport(crSubRepObj.SubreportName)
       Catch engEx As OutOfLicenseException
         CrystalErrorMessage = "Currently all of the available Crystal Reports Licenses are in use. Please wait a moment and try again."
            WriteToReportLog(CrystalEventID, CrystalReportName, "Error Creating SubReport", engEX.Message)
         Exit Sub
       Catch engEx As EngineException
               CrystalErrorMessage = engEx.Message
            WriteToReportLog(CrystalEventID, CrystalReportName, "Error Creating SubReport", engEX.Message)
         Exit Sub
       End Try
             crDatabase = crSubRepDoc.Database
       crTables = crDatabase.Tables
       For Each crTable In crTables
        With crConnInfo
          If UseRptServer = True And ReportingServerOnline Then
            .ServerName = ConfigurationSettings.AppSettings("ReportServerName")
            .DatabaseName = ConfigurationSettings.AppSettings("ReportDatabaseName")
            .UserID = ConfigurationSettings.AppSettings("ReportUserID")
            .Password = ConfigurationSettings.AppSettings("ReportPassWord")
          Else
            .ServerName = ConfigurationSettings.AppSettings("OLEDBServerName")
            .DatabaseName = ConfigurationSettings.AppSettings("OLEDBDatabaseName")
            .UserID = ConfigurationSettings.AppSettings("OLEDBUserID")
            .Password = ConfigurationSettings.AppSettings("OLEDBPassWord")
          End If
         End With
         crLogOnInfo = crTable.LogOnInfo
         crLogOnInfo.ConnectionInfo = crConnInfo
         crTable.ApplyLogOnInfo(crLogOnInfo)

         ' Commented out 11/13/2003 - Because of Database name change causing CR to probe SP with nulls
         ' --------------------------------------------------------------------------------------------
         'If InStr(crTable.Location.ToString, ".") Then
         '   If UseRptServer = True Then
         '   crTable.Location = ConfigurationSettings.AppSettings("ReportDatabaseName") & ".dbo." & _
         '                       crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
         '   Else
         '   crTable.Location = ConfigurationSettings.AppSettings("OLEDBDatabaseName") & ".dbo." & _
         '                       crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
         '   End If
         'End If

       Next
        End If
      Next
       Next

       i = 0
       crParamFieldDefs = crRepDoc.DataDefinition.ParameterFields
       For Each crParamFieldDef In crParamFieldDefs
      If crParamFieldDef.ParameterType = ParameterType.StoreProcedureParameter And _
            crParamFieldDef.IsLinked = False Then
        i = i + 1
        If UBound(CrystalParms) >= i Then
             Temp = CrystalParms(i)
        End If

        Select Case crParamFieldDef.ValueType
       Case FieldValueType.NumberField
         If Trim(Temp) = "" Then
        Temp = 0
         End If
         crParamDiscreteValue.Value = Convert.ToInt32(Temp)
         crParamValues = crParamFieldDef.CurrentValues
         crParamValues.Add(crParamDiscreteValue)
         crParamFieldDef.ApplyCurrentValues(crParamValues)

       Case FieldValueType.DateField, FieldValueType.DateTimeField
         Temp = Trim(Temp)
         If InStr(Temp, "/") < 4 Then
           Dim TempDate
           Dim strTemp
           If Instr(Temp, " ") = 0 Then
             TempDate = Temp
           Else
             TempDate = Left(Temp, InStr(Temp, " "))
           End if
           If Len(CStr(Month(TempDate))) < 2 Then
             Temp = CStr(Year(TempDate)) & "/0" & CStr(Month(TempDate))
           Else
             Temp = CStr(Year(TempDate)) & "/" & CStr(Month(TempDate))
           End If
           If Len(CStr(Day(TempDate))) < 2 Then
             Temp = Temp & "/0" & CStr(Day(TempDate))
           Else
             Temp = Temp & "/" & CStr(Day(TempDate))
           End If

           'add time if type DateTime, otherwise leave as just date
           If crParamFieldDef.ValueType = FieldValueType.DateTimeField Then
             Temp = Temp & " 00:00:00.000"
           End If
         End If

         Temp = Mid(Temp, 6, 2) & "/" & _
                      Mid(Temp, 9, 2) & "/" & _
                   Left(Temp, 4)

         crParamDiscreteValue.Value = CDate(Temp)
         crParamValues = crParamFieldDef.CurrentValues
         crParamValues.Add(crParamDiscreteValue)
         crParamFieldDef.ApplyCurrentValues(crParamValues)

       Case Else
         crParamDiscreteValue.Value = CStr(Temp)
         crParamValues = crParamFieldDef.CurrentValues
         crParamValues.Add(crParamDiscreteValue)
         crParamFieldDef.ApplyCurrentValues(crParamValues)
        End Select
      Else
        'Item.SetCurrentValue Item.DefaultValue,Item.ValueType
      End If
       Next

 TempReportPath = ConfigurationSettings.AppSettings("TempReportPath")

 If RptViewerType = "WORD" Then
   FName = TempReportPath & CrystalEventID & ".doc"
 Else 'default to Adobe Acrobat Reader
   FName = TempReportPath & CrystalEventID & ".pdf"
 End If

 crDiskFileDestOptions = New DiskFileDestinationOptions()
 crDiskFileDestOptions.DiskFileName = FName
 crExportOptions = crRepDoc.ExportOptions
 With crExportOptions
   .DestinationOptions = crDiskFileDestOptions
   .ExportDestinationType = ExportDestinationType.DiskFile
   If RptViewerType = "WORD" Then
  .ExportFormatType = ExportFormatType.WordForWindows
   Else 'default to Adobe Acrobat Reader
  .ExportFormatType = ExportFormatType.PortableDocFormat
   End If

 End With

 If myContext.Response.IsClientConnected = False Then
   TerminateCrystalReport()
 End If

 Try
   crRepDoc.Export()

 Catch engEx As OutOfLicenseException
   CrystalErrorMessage = "Currently all of the available Crystal Reports Licenses are in use. Please wait a moment and try again."
   WriteToReportLog(CrystalEventID, CrystalReportName, "Error During Export", engEX.Message)
   Exit Sub
 Catch engEx As EngineException
   CrystalErrorMessage = engEx.Message
   WriteToReportLog(CrystalEventID, CrystalReportName, "Error During Export", engEX.Message)
   Exit Sub
 Catch e As System.Exception
   CrystalErrorMessage = e.Message
   WriteToReportLog(CrystalEventID, CrystalReportName, "Error During Export", e.Message)
   Exit Sub
 End Try

 If myContext.Response.IsClientConnected = False Then
   TerminateCrystalReport()
 End If

 crRepDoc.Close()
 crSubRepDoc.Close()
 crRepDoc = Nothing
 crSubRepDoc = Nothing

 myContext.Response.ClearContent()
 myContext.Response.ClearHeaders()
 If RptViewerType = "WORD" Then
   myContext.Response.ContentType = "application/msword"
 Else 'default to Adobe Acrobat Reader
   myContext.Response.ContentType = "application/pdf"
 End If


 Try
   myContext.Response.WriteFile(FName)
 Catch e As System.IO.FileNotFoundException
   ErrorFound = True
   WriteToReportLog(CrystalEventID, CrystalReportName, "Error writing temp file to browser", e.message)
 Catch e As System.IO.IOException
   ErrorFound = True
   WriteToReportLog(CrystalEventID, CrystalReportName, "Error writing temp file", e.message)
 Catch e As System.Exception
   ErrorFound = True
   WriteToReportLog(CrystalEventID, CrystalReportName, "Error writing temp file", e.message)
 End Try

 myContext.Response.Flush()
 myContext.Response.Close()

 Try
   System.IO.File.Delete(FName)
 Catch e As System.IO.IOException
   ErrorFound = True
   WriteToReportLog(CrystalEventID, CrystalReportName, "Error deleting temp file", e.message)
 Catch e As System.Exception
   ErrorFound = True
   WriteToReportLog(CrystalEventID, CrystalReportName, "Error deleting temp file", e.message)

 End Try

 If ErrorFound = False Then
   WriteToReportLog(CrystalEventID, CrystalReportName, "Successful Report Processing", "No Error")
 End If

 CrystalErrorMessage = ""
  End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top