Skip to Content
0

I need to be able to choose PaperSource and set Duplex using vb.net

Oct 20, 2016 at 01:54 PM

50

avatar image

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.

10 |10000 characters needed characters left characters exceeded

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
Else
   rasPROpts.PrinterDuplex = CrystalDecisions.ReportAppServer.ReportDefModel.CrPrinterDuplexEnum.crPrinterDuplexDefault
End If


0

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

0
   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"
#Else
        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.")
        Else
            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.Load(strReportPath)
            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)
            Try
                'Added loop to keep all pages together when multiple copies are requested
                For i As Integer = 1 To (lnCopies)
                    rptClientDoc.PrintOutputController.PrintReport(rasPROpts)
                Next
            Catch ex As CrystalReportsException
                rptClientDoc.Close()
                crReportDocument = Nothing
                Call writelog("[ERR] Unable to create file [" + lcProcName + "]. Error message:" + ex.ToString)
            Catch ex As Exception
                rptClientDoc.Close()
                crReportDocument = Nothing
                Call writelog("[ERR] Unable to create file [" + lcProcName + "]. Error message:" + ex.ToString)
            Finally
                rptClientDoc.Close()
                crReportDocument = Nothing
                Call writelog("File [" + lcProcName + "] created Successfully")
                PrintSuccessful = True
            End Try
        End If
        'End If
        Return PrintSuccessful
    End Function

**********************************************************************************************
rptClientDoc.PrintOutputController.PrintReport(rasPROpts)
When this line runs, it throws a CrystalReportsException saying that the printer cannot be found.  The printer is in fact valid and without error.
0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Don Williams
Oct 20, 2016 at 07:56 PM
1

Hi Pat,

Try this : http://converter.telerik.com/

Don

Show 1 Share
10 |10000 characters needed characters left characters exceeded

That looks like it will be great! Thank you!

0