简体   繁体   中英

Crystal report printing to wrong printer

I'm troubleshooting an issue with a VB.NET app that I inherited.

The following lines execute print operation:

Me.rptShippingLabel1.PrintOptions.PrinterName = "LabelPrinter"
Me.rptShippingLabel1.PrintOptions.PaperOrientation =   CrystalDecisions.Shared.PaperOrientation.Landscape
Me.rptShippingLabel1.PrintToPrinter(Me.txtLabelQty.Text, False, 1, 1)

There is a Zebra ZDesign TLP2844 connected to workstations via direct USB and named LabelPrinter . However, despite target printer being specified in the code, that Zebra must be set as default printer in Windows, otherwise the job would go to any other printer set as default.
What's even more frustrating is that on some computers, with exactly the same configuration jobs go to correct printer but I can't identify controllable pattern. Any suggestions why might that be?

Reports in question are disassociated from printer in Design>Page Settings.

Look into your report. In page settings see if report is optimized for display. If yes, uncheck it. If report is optimized for displaying only, PrinterOptions enumeration is being discarded. You could still assign to Printer name property in older framework but not anymore.

Try the following code

    Dim rptShippingLabel1 As New CrystalReport1
    Dim PrinterSettings1 As New Printing.PrinterSettings
    Dim PageSettings1 As New Printing.PageSettings

    'Replace it with your printer name
    PrinterSettings1.PrinterName = "Microsoft XPS Document Writer"
    rptShippingLabel1.PrintToPrinter(PrinterSettings1, PageSettings1, False)

to get the printer name, don't read it from rptShippingLabel1.PrintOptions.PrinterName it will show blank. Try reading from PrinterSettings1.PrinterName.

This is tested with Crystal Reports runtime 13.0.9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM