on 03-02-2010 7:42 PM
I am having a difficult time getting our printers to print from a specific tray. I have set the papersource property to Upper, Lower, Middle, even Manual, and I cannot get the printer to choose the tray that I am sending. I have tried checking the No Printer option in Page Setup and checked the Dissociate Formatting Page Size and Printer Paper Size to no avail.
Any thought, Ideas...
Thanks,
Brad clark
This code works for me:
Public Function GetPaperSizeIndex(ByVal PaperName As String, Optional ByVal Impresora As String = "") As Integer
If PaperName.Trim.Length = 0 Then Return -1
If _PaperSizeArrayList Is Nothing OrElse _PaperSizeArrayList.Count > 0 OrElse Impresora <> _ultPrinterName Then
_PaperSizeArrayList = Me.GetPaperSizeList(Impresora)
_ultPrinterName = Impresora
End If
Try
For i As Integer = 0 To PaperSizeArrayList.Count
Dim wcomboitem As clsComboItem = PaperSizeArrayList.Item(i)
If UCase(PaperName) = UCase(wcomboitem.getDescripcion) Then
Return wcomboitem.getValor
End If
Next
Catch ex As Exception
Throw ex
End Try
Return -1
End Function
and to get de PaperSizeArrayList:
Private _PaperSizeArrayList As New ArrayList
Public Function GetPaperSizeList(Optional ByVal printername As String = "") As ArrayList
_PaperSizeArrayList.Clear()
Dim printdoc As New System.Drawing.Printing.PrintDocument
Try
If printername <> "" Then
printdoc.PrinterSettings.PrinterName = printername
End If
For Each pksize As PaperSize In printdoc.PrinterSettings.PaperSizes
_PaperSizeArrayList.Add(New clsComboItem(pksize.RawKind, pksize.PaperName))
Next
Catch ex As Exception
MsgBox("GetPaperSizeList:" & ex.Message)
End Try
Return _PaperSizeArrayList
End Function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the spirit of hopefully helping someone out, here's what worked for me:
Within Crystal Reports, the Print Setup was set to use "letter" size paper. But no matter which PaperSource I selected, the job always printed to the lower tray, which happens to be filled with letter-size paper.
The fix was to also set the PaperSize value...
So in my case, this failed to take effect:
CReport.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Middle
But this succeeded:
CReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperLegal
CReport.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Middle
The lesson learned was that if the PaperSize setting in the RPT file does not match up to the actual physical paper size specified PaperSource setting in code, the print job will automatically switch over to another PaperSource that does have the correct media size. Which will present to you as "no matter what I do, it doesn't work!"
I ended up using this code to achieve what I needed:
CReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperLetter
CReport.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Lower
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will probably have to find the enum for the tray and set that. Download the devcap utility from here:
and see what it tells you for the enum. Then set that to the PaperSource property in your code.
Ludek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had the exact same problem with my HP LaserJet P4015 printers. We just switched from HP LaserJet 4350 printers - and we were setting the PaperSource to print to Tray2 just fine. Now it has no effect. It always prints to Tray 3 instead of the Letterhead tray (Tray2).
To make it work, we switched to using the PrintOptions.CustomPaperSource instead - this allows you to set the RawKind to a number that is returned from the printers PaperSource.RawKind when you find a papersource that matches the one you want to use. This is generic for changes in the tray numbers - which happens every time you change drivers - it also allows us to have the PaperSource for each report in the database - which overrides what is in the RPT file.
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
pd.PrinterSettings.PrinterName = MyReport.PrinterName;
foreach (System.Drawing.Printing.PaperSource ps in pd.PrinterSettings.PaperSources)
{
//Trim data from Driver, and take the first one that Starts with our PaperSource name (ie: 'Auto' matches 'Automatically Select' and 'Auto Select')
if (ps.SourceName.Trim().StartsWith(MyReport.PaperSource))
{
MyCrystalReport.ReportDoc.PrintOptions.CustomPaperSource = new System.Drawing.Printing.PaperSource();
MyCrystalReport.ReportDoc.PrintOptions.CustomPaperSource.RawKind = ps.RawKind;
break;
}
}
//If nothing matches MyReport.PaperSource it will use the papersource in the crystal RPT file instead of MyReport.PaperSource.
David
When I run the program I get the following:
Bin Info:
Supported Bin Types:
15 USER DEFINED
259 USER DEFINED
258 USER DEFINED
257 USER DEFINED
Named bins:
Automatically Select
Cont. Feed - No Break
Cut Sheet
Cont. Feed - With Break
Let me give you a little more detail. I am writing a DOT Net application that calls a Crystal Report and prints it to a defined tray. I need this application to work so we can get rid of a piece of software that we are using called "Optio". This "Optio" software uses the exact same driver (from the same server) as the one I pulled the information from above using the DevCap utility. The Optio application is set to print to "Upper" and it works. Although, no matter what I do everything prints to the Tray 1 manual. They have the printer loaded with White Paper in the manual tray and Yellow paper in the Tray 1 (upper tray).
I have tried the following "PaperSource" values:
PaperSouce.Lower
PaperSouce.Middle
PaperSouce.Upper
PaperSouce.Manual
Then, I tried the values from above:
15
257
258
259
Also, I tried using the other suggestion and setting the "RawKind". I queried the PaperSources using the code provided and retrieved the value for the "Tray 1" and used that.
All of these just send the output to the White Paper in the "flip-out" Tray 1 "Manual" tray...
Any suggestions, anyone?
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.