2011-07-15 14 views
5

कोई प्रिंटर पर सभी प्रिंट ट्रे खोजने और उनके पेपर आकारों को खोजने का कोई तरीका है उदा।.NET पेपर ट्रे आकार

Tray1 = A4 
Tray2 = A3 
Tray3 = Letter 

मैं इस तरह कुछ उपयोग करके ट्रे प्राप्त करने का एक तरीका देख सकता हूं लेकिन इसमें पेपर आकार की जानकारी प्रतीत नहीं होती है।

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

जो मैं करना चाहता हूं वह डिफ़ॉल्ट रूप से प्रिंट नौकरी के लिए सबसे अच्छा ट्रे चुनना है।

+0

क्या यह वेब एप्लिकेशन या डब्ल्यूपीएफ है? – Ankit

+0

इसकी एक विनफॉर्म परियोजना – PeteT

+0

बस सोच रही है .. यदि आप केवल प्रिंट नौकरी के लिए सबसे अच्छी ट्रे की तलाश में हैं, तो क्यों न केवल सबसे बड़ी ट्रे का उपयोग करें और पेपर आकार निर्दिष्ट करें ?? –

उत्तर

3
  1. आप प्रिंटर गुण जो प्रिंटर के लिए कागज डिब्बे (ट्रे) Windows API का उपयोग कर शामिल प्राप्त कर सकते हैं: http://msdn.microsoft.com/en-us/library/bb258176(v=office.12).aspx http://www.thedbcommunity.com/index.php?option=com_content & कार्य = दृश्य & आईडी = 218 & Itemid = 56

  2. आप ArcObjects एसडीके 10 Microsoft.NET फ्रेमवर्क में IPAPER वर्ग (मैं यह कैसे काम करता काफी यकीन नहीं कर रहा हूँ) http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002wn000000

  3. इस्तेमाल कर सकते हैं

संपादित करें: बस लिंक मैं तुम्हें दे दी है में से एक पर गहराई से अवलोकन ले लिया है, इस सवाल का जवाब आप देख रहे हैं होना चाहिए: प्रतिबंध के कारण, आप कर सकते हैं

// 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; 
     } 

वेबसाइट से आंशिक रूप से कॉपी किया गया यहाँ पूर्ण कोड देखने:

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

2

चेक MSDN से इस कोड। या तुमने कोशिश की? हो सकता है कि आप ट्रे नाम के साथ पेपरसाइज नाम से मेल खा सकें।

// Add list of supported paper sizes found on the printer. 
    // The DisplayMember property is used to identify the property that will provide the display string. 
    comboPaperSize.DisplayMember = "PaperName"; 

    PaperSize pkSize; 
    for (int i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++){ 
     pkSize = printDoc.PrinterSettings.PaperSizes[i]; 
     comboPaperSize.Items.Add(pkSize); 
    } 

    // Create a PaperSize and specify the custom paper size through the constructor and add to combobox. 
    PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200); 

    comboPaperSize.Items.Add(pkCustomSize1); 
+0

क्या आपको पता है कि वास्तव में comboPaperSize क्या है? – David

2

मुझे लगता है कि सी # में एक आसान तरीका PrintDocument प्रिंटर सेटिंग क्वेरी करने के लिए है।

PrintDocument printDoc = new PrintDocument(); 
PrinterSettings printSettings = printDoc.PrinterSettings; 

for (int i=0; i < printSettings.PaperSources.Count; i++) 
{ 
    sTmp += printSettings.PaperSources[i].SourceName; 
    sTmp += " : "; 
    sTmp += printSettings.PaperSources[i].Kind.ToString(); 
    sTmp += " : "; 
    sTmp += printSettings.PaperSources[i].RawKind.ToString(); 
    sTmp += "\n"; 
} 

MessageBox.Show(sTmp, "Paper Sources for " + printSettings.PrinterName+ " : " + 
        printSettings.IsDefaultPrinter.ToString()); 

अगर मैं "ट्रे 2" SOURCENAME में देखने के लिए और RawKind उपयोग करते हैं, मैं Winspool.drv आयात करने के लिए होने के साथ ऊपर GetBinNumber रूप में एक ही जवाब मिलता है।

क्या मुझे कुछ याद आ रही है?

संबंधित मुद्दे