0

HI Guys,

I have written an app the prints out batches of documents for postings. Each batch is to be seperated by a red coversheet.

I know that in our printing department, no matter what printer they use to print the batches on to they will always have the red paper in Tray 2.

My issue is that when I create my coversheet as a word doc and go to print it, I want to point it at this tray. I found the tray using System.drawing.printer settings and I tried to point the Word doc at this tray but I got the following build error:

Error 1 Value of type 'System.Drawing.Printing.PaperSource' cannot be converted to 'Word.WdPaperTray'.

My code to find the tray is this ( the printer has already been selected by a combobox and I'm putting the trays into another combo so they can override):

dim strPrinter as string
 strPrinter = cbBlackWhite.SelectedItem
cbRedTray.DisplayMember = "SourceName"
        printDoc.PrinterSettings.PrinterName = strPrinter
        For intTray = 0 To printDoc.PrinterSettings.PaperSources.Count - 1
            pkSource = printDoc.PrinterSettings.PaperSources.Item(intTray)
            cbRedTray.Items.Add(pkSource)
            If UCase(Trim(pkSource.SourceName)) = "TRAY 2" Then
                intRedTray = intTray
            End If
        Next
        cbRedTray.SelectedIndex = intRedTray

Then when I'm printing the coversheet I was trying to use:

oDoc.PageSetup.FirstPageTray = cbRedTray.SelectedItem
oDoc.PageSetup.OtherPagesTray = cbRedTray.SelectedItem

So my question is should is there a way to convert one type to the other or which method should I be using to specify the tray?

In other words, is there a way in Word to parse through trays and get them back ? Or am I looking at using system.drawing?

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by G_Waddell
0

Hi I figured it out myself:

Code for Populating combobox:

Dim pkSource As Printing.PaperSource
        Dim strPrinter As String
        Dim printDoc As New Printing.PrintDocument
        Dim intTray As Integer
        Dim intRedTray As Integer = 0
        cbRedTray.Items.Clear()
        ' Add list of paper sources found on the printer to the combo box.
        ' The DisplayMember property is used to identify the property that will provide the display string.
        strPrinter = cbBlackWhite.SelectedItem
        printDoc.PrinterSettings.PrinterName = strPrinter
        For intTray = 0 To printDoc.PrinterSettings.PaperSources.Count - 1
            pkSource = printDoc.PrinterSettings.PaperSources.Item(intTray)
            cbRedTray.Items.Add(New DataItem(pkSource.RawKind, pkSource.SourceName))
            If UCase(Trim(pkSource.SourceName)) = "TRAY 2" Then
                intRedTray = intTray
            End If
        Next
        cbRedTray.SelectedIndex = intRedTray

And then where I handle the word document:

dim DI as DataItem = cbRedTray.SelectedItem
dim lngTray as Long 
dim oWord as New Word.application
dim oDoc as Word.Document
....
lngTray = DI.ID
oDocPageSetup.FirstPageTray = lngTray
oDoc.PageSetup.OtherPagesTray = lngTray
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.