Skip to Content
0
Former Member
Sep 05, 2012 at 01:36 PM

StartPageNumber and EndPageNumber being ignored when exporting to ByteArray

21 Views

Hello,

We recently upgraded some code from VS2005 to VS2010 and we are now referencing the BI 4.0 SDK DLLs. For the most part our conversion has gone well with a couple of exceptions. One of those is an issue when we export a Crystal Report to a ByteArray. This ByteArray is used to create a PDF in a follow-on process. Under certain circumstances for some reports we only want to export a certain range of pages. This functionality has been working with the VS2005 version of our application, but when we upgraded to the new BI 4.0 SDK DLLs it seems to ignore the StartPageNumber and EndPageNumber. For instance, the report we are using to test with has 36 pages. If we say we want pages 1 to 3 we still get all 36 pages. I've provided the code we are using below:

Public Function ExportReportToByteArray(ByVal intReportID As Integer, _
ByVal ParameterBag As List(Of ParameterInfo), _
ByVal theExportFormat As ExportFormat, _
ByVal theInfoStore As InfoStore, _
ByVal RecordSelectionFormula As String, _
Optional ByVal StartingPageNbr As Integer = 1, _
Optional ByVal EndingPageNbr As Integer = 0, _
Optional ByVal strDBServerName As String = "", _
Optional ByVal strDBDatabaseName As String = "", _
Optional ByVal strDBUsername As String = "", _
Optional ByVal strDBPassword As String = "") As ByteArray

Dim myReportClientDocument As ReportClientDocument
Dim myBytes As ByteArray = Nothing
Dim myType As String = Nothing

Try
Dim myObject As Object = theInfoStore.EnterpriseSession.GetService("", "RASReportFactory").Interface
Dim myReportAppFactory As ReportAppFactory = CType(myObject, ReportAppFactory)
myReportClientDocument = myReportAppFactory.OpenDocument(intReportID, 0)
'--------------------------------------------------------
'- We need to set the database login information if it
'- has been supplied . . .
'--------------------------------------------------------
If strDBServerName.Length > 0 Then
myReportClientDocument = SetDatabaseRAS(myReportClientDocument, strDBServerName, strDBDatabaseName,

strDBUsername, strDBPassword)
End If
Catch ex As Exception
Throw New Exception("Error getting the report to be exported.", ex)
End Try

Try
CopyParameterBagToReportClientDoc(ParameterBag, myReportClientDocument)
Catch ex As Exception
Throw New Exception("Error setting the parameters for the report to be exported.", ex)
End Try

If RecordSelectionFormula.Length > 0 Then
myReportClientDocument.DataDefController.RecordFilterController.SetFormulaText(RecordSelectionFormula)
End If

Try
Select Case theExportFormat
Case ExportFormat.MSExcel
Dim excelOptions As ExcelExportFormatOptions = New ExcelExportFormatOptionsClass
Dim excelExportOptions As ExportOptions = New ExportOptions

If EndingPageNbr > 0 Then
excelOptions.StartPageNumber = StartingPageNbr
excelOptions.EndPageNumber = EndingPageNbr
End If
excelExportOptions.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatMSExcel
excelExportOptions.FormatOptions = excelOptions

myBytes = myReportClientDocument.PrintOutputController.ExportEx(excelExportOptions)

myType = "application/msexcel"
Case ExportFormat.MSExcelDataOnly
Dim excelOptions As ExcelExportFormatOptions = New ExcelExportFormatOptionsClass
Dim excelExportOptions As ExportOptions = New ExportOptions

If EndingPageNbr > 0 Then
excelOptions.StartPageNumber = StartingPageNbr
excelOptions.EndPageNumber = EndingPageNbr
End If
excelExportOptions.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatRecordToMSExcel
excelExportOptions.FormatOptions = excelOptions

myBytes = myReportClientDocument.PrintOutputController.ExportEx(excelExportOptions)

myType = "application/msexcel"
Case ExportFormat.PDF
'------------------------------------------------
'- Revised Code . . .
'------------------------------------------------
Dim pdfOptions As New PDFExportFormatOptions
Dim pdfExportOptions As New ExportOptions

pdfOptions.CreateBookmarksFromGroupTree = False

pdfOptions.StartPageNumber = StartingPageNbr
pdfOptions.EndPageNumber = EndingPageNbr

pdfExportOptions.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatPDF
pdfExportOptions.FormatOptions = pdfOptions

myBytes = myReportClientDocument.PrintOutputController.ExportEx(pdfExportOptions)

myType = "application/pdf"

Case ExportFormat.MSWord
Dim wordOptions As RTFWordExportFormatOptions = New RTFWordExportFormatOptionsClass
Dim wordExportOptions As ExportOptions = New ExportOptions

If EndingPageNbr > 0 Then
wordOptions.StartPageNumber = StartingPageNbr
wordOptions.EndPageNumber = EndingPageNbr
End If
wordExportOptions.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatMSWord
wordExportOptions.FormatOptions = wordOptions

myBytes = myReportClientDocument.PrintOutputController.ExportEx(wordExportOptions)
myType = "application/msword"
End Select
Catch ex As Exception
Throw New Exception("Error exporting the report to ByteArray.", ex)
End Try

Return myBytes

End Function

Are we missing something in our code or is there a Service Pack we need to apply in order for the page range to be recognized. Any help is greatly appreciated.

Thanks