I am trying to merge multiple pdf files created from Crystal Reports. The first one is created and will always show, then based on criteria, others are appended. Sample Code:
Dim sReport As New MemoryStream
Dim doc As MergeDocument
Dim QuoteReportSource As New CrystalReportSource
Dim quoteRpt As New Report
quoteRpt.FileName = "Quote.rpt"
QuoteReportSource.Report = quoteRpt
QuoteReportSource.ReportDocument.SetDatabaseLogon(crUserName, crPassword)
QuoteReportSource.ReportDocument.SetParameterValue("@QuoteID", quoteID)
sReport = QuoteReportSource.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
doc = New MergeDocument(New PdfDocument(sReport))
PrintQuote(quoteID, doc, crUserName, crPassword)
This gets the first generated pdf from crystal reports (Quote.rpt) exports it to the memory stream, and then the merge document is created from that. The last line (PrintQuote()), calls a function that will determine what others need appending. It is shown below:
Private Sub PrintQuote(ByVal quoteID As Integer, ByVal quoteDoc As MergeDocument, ByVal crUserName As String, ByVal crPassword As String, ByVal startPos As Integer)
Dim db As New ArtisansLinqDataContext
Dim company = (From d In db.WorksheetDetails Where d.QuoteID = quoteID Select d.CompanyName).First
Dim triaSource As New CrystalReportSource
Dim triaRpt As New Report
Dim triaStream As New MemoryStream
If company = "Colony Insurance" Then
triaRpt.FileName = "Colony/ColonyTRIA.rpt"
triaSource.Report = triaRpt
triaSource.ReportDocument.SetDatabaseLogon(crUserName, crPassword)
triaSource.ReportDocument.SetParameterValue("@QuoteID", quoteID)
triaStream = triaSource.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
quoteDoc.Append(New PdfDocument(triaStream))
End If
quoteDoc.DrawToWeb(String.Format("JJArtisansQuote_{0}.pdf", quoteID), True)
End Sub
Now, what happens is if the condition is met, there are 2 pages to the merged pdf, as there should be (one for the quote.rpt, and one for the ColonyTRIA.rpt), bu both pages hold the quote.rpt - it's as if that first just gets repeated in the append.
If the condition isn't met, then it does just the one page as it should. Am I using the memory stream incorrectly here, or am I trying to do something that can't be done?
Thank you,