Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6170795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:06:09+00:00 2026-05-23T23:06:09+00:00

Is there a way to find all print trays on a printer and get

  • 0

Is there a way to find all print trays on a printer and get their paper sizes e.g.

Tray1 = A4
Tray2 = A3
Tray3 = Letter

I can see a way to get the Trays using something like this but it doesn’t seem to have the paper size information.

using (System.Drawing.Printing.PrintDocument doc = new PrintDocument())
{
    foreach (System.Drawing.Printing.PaperSource paperSource in doc.PrinterSettings.PaperSources)
    {
        string trayName = paperSource.SourceName;
    }
}

What I am wanting to do is select the best Tray for the print job by default.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:06:09+00:00Added an answer on May 23, 2026 at 11:06 pm
    1. You can get the printer properties which includes the paper bins (trays) for the printer using windows api:
      http://msdn.microsoft.com/en-us/library/bb258176(v=office.12).aspx
      http://www.thedbcommunity.com/index.php?option=com_content&task=view&id=218&Itemid=56

    2. You could use the IPaper class in ArcObjects SDK 10 Microsoft.NET Framework (I am not quite sure about how this works)
      http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002wn000000

    Edit: Just took an in depth look on one of the links I gave you, this should be the answer you’re looking for:

    // Get Printer Tray Codes for Word Printing using DeviceCapabilities
    // By: BB
    //
    // Inputs:1)strTrayName - Name of the tray to search for, ie "Tray 1", "Tray 2", "Manual"
    
            /// <summary>
            /// Gets the printer code for the specified tray, based on the current printer for the Word Document
            /// Printer trays on various HP printers change between models and Word documents 
            /// will not act the same when printed on different printers. This allows us
            /// to get the right code for the tray we want to print to.
            /// </summary>
            /// <param name="strTrayName">Name of the tray to search for, ie "Tray 1", "Tray 2", "Manual"</param>
            /// <param name="iDefaultBin">A default bin to return if not found ie. (int)WdPaperTray.wdPrinterUpperBin</param>
            /// <param name="wordDoc">A word document object that we want to check the printer for</param>
            /// <returns></returns>
            public int GetBinNumber(string strTrayName, int iDefaultBin, Word.Document wordDoc)
            {
                //Code adapted from Microsoft KB article Q194789
                //HOWTO: Determine Available PaperBins with DeviceCapabilities API
                //Get the printer & port names and numbers of the current printer
                // 
                // Once we have the printer bin we can then use 
                // InvokeMember on the wordDoc.PageSetup object to set the bin.
                //
                // Example call to this method is 
                // int Tray1Code = GetBinNumber("Tray 1",(int)WdPaperTray.wdPrinterUpperBin);
                int BinRes;
                BinRes = iDefaultBin; //set up a default bin as the lower
                try
                {
                    string sPort = wordDoc.Application.ActivePrinter.Substring(wordDoc.Application.ActivePrinter.IndexOf(" on ") + 3).Trim();
                    string sCurrentPrinter = wordDoc.Application.ActivePrinter.Substring(0, wordDoc.Application.ActivePrinter.IndexOf(" on ")).Trim();
                    //'Find out how many printer bins there are
                    Int32 iBinCnt = DeviceCapabilities(sCurrentPrinter, sPort, DC_BINS, null, IntPtr.Zero);
                    if (iBinCnt > -1)
                    {
                        //'Set the array of bin numbers to the right size
                        UInt16[] iBinArray = new UInt16[iBinCnt];
                        //set up a buffer to receive the bin names - each name is up to 24 chars, null terminated
                        byte[] buffer = new byte[iBinCnt * 24];
                        // Load the array with the bin numbers
                        iBinCnt = DeviceCapabilitiesA(sCurrentPrinter, sPort, DC_BINS, iBinArray, IntPtr.Zero);
                        if (iBinCnt > -1)
                        {
                            // Load the array of bin names
                            iBinCnt = DeviceCapabilitiesA(sCurrentPrinter, sPort, DC_BINNAMES, buffer, IntPtr.Zero);
                            if (iBinCnt > -1)
                            {
                                string sBinNames = Encoding.ASCII.GetString(buffer, 0, buffer.Length);
                                //split the null terminated strings into a string array for searching
                                while (sBinNames.IndexOf("\0\0") > -1) 
                                {
                                    sBinNames = sBinNames.Replace("\0\0", "\0");
                                }
                                string[] arrBinNames = sBinNames.Split('\0');
                                //System.Diagnostics.Debug.WriteLine("prn nams = " + res );
                                int idx = 0;
                                foreach (string BinNam in arrBinNames)
                                {
                                    if( BinNam.Trim().StartsWith(strTrayName))
                                    {
                                        BinRes = iBinArray[idx];
                                        break;
                                    }
                                    idx++;
                                }
    
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Error - " + ex.Message );
                }
                return BinRes;
            }
    

    Copied partly from the website due to restrictions, you can view the full code here:

    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3687&lngWId=10

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a way to find all script files added to a page in
in visual studio 6 is there a way to Find All References. Don't see
I'm using rails 2.3.5 with i18n. I's there a way to find all not
Is there a better way to find all form elements in a Drupal form
Is there some way I can find all active spies in sinon.js? I'd like
Is there a way I can find out all changes to memory by a
Is there a way to create a condition like this? @products = Product.find(:all, :limit
I'm wondering if there is a way to print out all accessible variables in
Is there another way to find out the status of services on AppEngine other
Is there a way to find out which Javascript function is fired by click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.