Skip to Content
avatar image
Former Member

I need to be able to choose PaperSource and set Duplex using

I have code I have written for this purpose using C# but cannot find how to translate it to vb. Examples of C# code are as follows...

rasPROpts.PaperSource = (CrPaperSourceEnum)lnTrayVal;

rasPROpts.PrinterDuplex = (CrystalDecisions.ReportAppServer.ReportDefModel.CrPrinterDuplexEnum)lnDuplex;

The lnTrayVal has been determined with prior code.

lnDuplex is sent as "1", "2", or "3"

Can you help me out, Please.

Add comment
10|10000 characters needed characters exceeded

  • Former Member

    I have written the following to handle the Duplex but still have no answers to the PaperSource

    If lnDuplex = 1 Then
       rasPROpts.PrinterDuplex = CrystalDecisions.ReportAppServer.ReportDefModel.CrPrinterDuplexEnum.crPrinterDuplexSimplex
    ElseIf lnDuplex = 2 Then
       rasPROpts.PrinterDuplex = CrystalDecisions.ReportAppServer.ReportDefModel.CrPrinterDuplexEnum.crPrinterDuplexVertical
    ElseIf lnDuplex = 3 Then
       rasPROpts.PrinterDuplex = CrystalDecisions.ReportAppServer.ReportDefModel.CrPrinterDuplexEnum.crPrinterDuplexHorizontal
       rasPROpts.PrinterDuplex = CrystalDecisions.ReportAppServer.ReportDefModel.CrPrinterDuplexEnum.crPrinterDuplexDefault
    End If
  • Former Member Former Member

    Further testing shows that this will not allow choice of trays or duplex etc.

  • Former Member
       Public Function PrintReport() As Boolean
            Dim PrintSuccessful As Boolean = False
            Dim llError As Boolean = False
            Dim ds As New DataSet()
            Dim rowCount As Integer
            Dim filePath As String = lxReportXml
            Dim lcReport As String = ""
            'ds.ReadXml(filePath, XmlReadMode.Auto)
            If lcProcName = "CSPREQ01" Then
                rowCount = TMINVCHD.Rows.Count
                lcReport = "Parts Report Request"
            ElseIf lcProcName = "CSREPR01" Then
                rowCount = tmreprdb.Rows.Count
                lcReport = "Customer Service Repair Request Worksheet"
            End If
    #If DEBUG Then
            Dim strReportPath As String = CrystalFilesTesting + lcProcName + ".rpt"
            Dim strReportPath As String = CrystalFiles + lcProcName + ".rpt"
    #End If
            If Not (File.Exists(strReportPath)) Then
                PrintSuccessful = False
                Call writelog("[ERR] Crystal Report File [" + strReportPath + "] does not exist.")
                Dim crPrintDocument As New System.Drawing.Printing.PrintDocument()
                Dim rasPROpts As New CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions()
                Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
                crReportDocument.SummaryInfo.ReportTitle = lcReport
                Dim printerSettings As New System.Drawing.Printing.PrinterSettings()
                Dim pSettings As New System.Drawing.Printing.PageSettings(printerSettings)
                Dim RASPO As New CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions()
                pSettings.PaperSource.RawKind = (lnTrayVal)
                Dim pDoc As New System.Drawing.Printing.PrintDocument()
                Dim PrintLayout As New CrystalDecisions.Shared.PrintLayoutSettings()
                RASPO.DissociatePageSizeAndPrinterPaperSize = True
                Dim rptClientDoc As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument
                rptClientDoc = New CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocument(crReportDocument)
                rptClientDoc = crReportDocument.ReportClientDocument
                rasPROpts.PrinterDuplex = DirectCast(lnDuplex, CrystalDecisions.ReportAppServer.ReportDefModel.CrPrinterDuplexEnum)
                rasPROpts.JobTitle = lcReport
                rasPROpts.PrinterName = lcPrinter
                rasPROpts.PaperSource = DirectCast(lnTrayVal, CrPaperSourceEnum)
                rasPROpts.NumberOfCopies = 1
                'rasPROpts.PaperSource = DirectCast(lnTrayVal, CrPaperSourceEnum)
                    'Added loop to keep all pages together when multiple copies are requested
                    For i As Integer = 1 To (lnCopies)
                Catch ex As CrystalReportsException
                    crReportDocument = Nothing
                    Call writelog("[ERR] Unable to create file [" + lcProcName + "]. Error message:" + ex.ToString)
                Catch ex As Exception
                    crReportDocument = Nothing
                    Call writelog("[ERR] Unable to create file [" + lcProcName + "]. Error message:" + ex.ToString)
                    crReportDocument = Nothing
                    Call writelog("File [" + lcProcName + "] created Successfully")
                    PrintSuccessful = True
                End Try
            End If
            'End If
            Return PrintSuccessful
        End Function
    When this line runs, it throws a CrystalReportsException saying that the printer cannot be found.  The printer is in fact valid and without error.
  • Get RSS Feed

1 Answer

  • Best Answer
    Oct 20, 2016 at 07:56 PM

    Hi Pat,

    Try this :


    Add comment
    10|10000 characters needed characters exceeded