[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Crystal Reports Printing


When I call the PrintReport method of the CrystalReportViewer in VB.NET 2003, it brings up the Windows Print dialog box (the one where you can select the printer and so on). How can I make it so that it just prints, to the default printer if necessary, without bringing up the Windows Print dialog? I need to do this because I wrote a software which has to perform batch printing of many Crystal Reports, and the user should'nt have to click "Print" every time.

Thanks for your support
  • 2
1 Solution
This might work for you.
I use this to print with the Acrobat 6.0 Reader......


Imports System.IO

    Public Function InitializeDefaultPrinter()
        ' Set the specified printer to the default printer for this program. Return
        ' true if the printer was found.

        Dim objprinter As PageSettings = New PageSettings
        Dim strname = objprinter.PrinterSettings.PrinterName

        InitializeDefaultPrinter = strname
    End Function
    Public Sub PrintReports()
        Cursor.Current = Cursors.WaitCursor
        ' Dim frm As New frmCrDates

        Dim regKey As RegistryKey
        Dim sPrinterDriver As String
        Dim sPrinterPort As String
        Dim myProcess As New Process
        Dim sDefaultPrinter As String
        Dim keyValue As String

        'To get the Printer driver...
        sDefaultPrinter = InitializeDefaultPrinter()
        'Added 10-25-2004 for server printers
        'If sDefaultPrinter.StartsWith("\") Then
        '    sDefaultPrinter = sDefaultPrinter.Substring(2)
        'End If
        keyValue = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\" & sDefaultPrinter
        regKey = Registry.LocalMachine.OpenSubKey(keyValue, False)
        sPrinterDriver = regKey.GetValue("Printer Driver", 0)
        sPrinterPort = regKey.GetValue("Port", 0)

            Dim di As New DirectoryInfo(sAppPath & sReportPath & "Acrobat\")
            Dim fi As FileInfo() = di.GetFiles()
            Dim fiTemp As FileInfo
            Dim i As Short
            Dim j As Short = 20
            'Run this EXE to print files sReader = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"
            Dim startInfo As New ProcessStartInfo(sReader)
            startInfo.WindowStyle = ProcessWindowStyle.Hidden
            startInfo.CreateNoWindow = True
            For Each fiTemp In fi
                startInfo.Arguments = "/t """ & fiTemp.FullName & """ """ & sDefaultPrinter & """ """ & sPrinterDriver & """ """ & sPrinterPort & """"
                startInfo.UseShellExecute = False
                'Use delay to wait for printer to print files in 30 file units
                i += 1
                Select Case i
                    Case j
                        delay(2000)  '2 mins.
                        j += 30
                End Select
            Next fiTemp
        Catch Exp As Exception
            MsgBox(Exp.Message & "   in Print Report Procedure", MsgBoxStyle.Critical, "General Error")
        End Try
        Cursor.Current = Cursors.Default
    End Sub
SETPAuthor Commented:
WOW! That's quite a solution you poseted there! Will the client need Acrobat Reader installed?
Yes it is Free from Adobe.

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now