Results 1 to 2 of 2

Thread: Print Crystal Report to Disk

Hybrid View

  1. #1
    New Member
    Join Date
    May 12
    Posts
    2

    Print Crystal Report to Disk

    Hi, I'm very new to VB.NET and am in need for some help.
    For 2 days I'm now trying to get my code to print a PDF from Crystal to PDF.

    I'm trying to translate a VB6 program to VB.Net 2010.
    This is the VB6 program. All it does is, take an existing report and print a pdf to disk.
    The only reason I want to migrate it to VB.NET is because in VB6 I don't seem to be able to export Group Headers as PDF bookmarks.
    If anyone know a way of exporting group headers as bookmarks I can save me the whole .net translation.

    Code:
    Dim crystal As CRAXDRT.Application
    Dim report As CRAXDRT.report       
    Set crystal = CreateObject("CrystalRuntime.Application.10")
    Set report = crystal.OpenReport("c:\Balances.rpt")
    
    report.EnableParameterPrompting = False
    Set Parameters = report.ParameterFields
    For cnt = 1 To Parameters.Count
      Set Parameters = Parameters.Item(cnt)
      If Parameters.Name = "{?Country}" Then
        Parameters.ClearCurrentValueAndRange
        Parameters.AddCurrentValue "10" 'Tanzania
      End If
    Next
    
    'report.ExportOptions.CreateBookmarksFromGroupTree = True
    report.ExportOptions.DiskFileName = "c:\Balances.pdf"
    report.ExportOptions.FormatType = crEFTPortableDocFormat
    report.ExportOptions.DestinationType = crEDTDiskFile
    report.ExportOptions.PDFExportAllPages = True
    report.Export False
    
    Set report = Nothing
    Set crystal = Nothing


    I've started in VB.Net already but can simply not get it to work.
    I'm testing with CR XI R2 and Visual Studio 2010.

    I start by creating a new Crystal Reports Application and choose the report I want to use. I figure this might not be necessary as I don't want anything to display, just run the .exe to print the pdf as an scheduled process later on.
    I've removed the CrystalReportViewer and the CrystalReportDocument control from my form and just added a button to test it.

    This is my code:
    Code:
    Imports CrystalDecisions.Shared
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Windows.Forms
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim crReport As ReportDocument
                Dim crPDFOptions As PdfFormatOptions
    
                Dim strFileName As String
                Dim reportPath As String = ""
    
                strFileName = "test"
                crReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument ' here it throws an exception
    
                crReport.Load("c:\Balances.rpt", OpenReportMethod.OpenReportByTempCopy)
    
                crPDFOptions = New PdfFormatOptions()
                crPDFOptions.CreateBookmarksFromGroupTree = True
    
                Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
                Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
                CrDiskFileDestinationOptions.DiskFileName = "C:\" & strFileName & ".pdf"
                With crReport.ExportOptions
                    .ExportDestinationType = ExportDestinationType.DiskFile
                    .ExportFormatType = ExportFormatType.PortableDocFormat
                    .DestinationOptions = CrDiskFileDestinationOptions
                    .FormatOptions = CrFormatTypeOptions
                End With
                crReport.Export()
    
                crReport = Nothing
                CrDiskFileDestinationOptions = Nothing
                CrFormatTypeOptions = Nothing
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End Sub
    End Class
    The exception it throws at crReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument is the following.

    "Retrieving the COM class factory for component with CLSID {4DB2E2BB-78E6-4AEA-BEFB-FDAAB610FD1B} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."

    I don't have any references to a COM class and don't hink I should have.
    But this is about all I can read from that error.

    Any help is really appreciated.

  2. #2
    New Member
    Join Date
    May 12
    Posts
    2

    Re: Print Crystal Report to Disk

    Changing the Target CPU to x86 fixed my problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •