■ PrintQueue 클래스의 MergeAndValidatePrintTicket 메소드를 사용해 양면 인쇄 기능을 활성화하는 방법을 보여준다.
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
using System; using System.Printing; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 사용법 표시하기 - DisplayUsage() /// <summary> /// 사용법 표시하기 /// </summary> private static void DisplayUsage() { Console.WriteLine(); Console.WriteLine("Usage #1: printticket.exe -l \"<printer_name>\""); Console.WriteLine(" Run program on the specified local printer"); Console.WriteLine(); Console.WriteLine(" Quotation marks may be omitted if there are no spaces in printer_name."); Console.WriteLine(); Console.WriteLine("Usage #2: printticket.exe -r \"\\\\<server_name>\\<printer_name>\""); Console.WriteLine(" Run program on the specified network printer"); Console.WriteLine(); Console.WriteLine(" Quotation marks may be omitted if there are no spaces in server_name or printer_name."); Console.WriteLine(); Console.WriteLine("Usage #3: printticket.exe -a"); Console.WriteLine(" Run program on all installed printers"); Console.WriteLine(); } #endregion #region 인쇄 티켓 설정 변경하기 - ChangePrintTicketSetting(printQueue) /// <summary> /// 인쇄 티켓 설정 변경하기 /// </summary> /// <param name="printQueue">인쇄 큐</param> private static void ChangePrintTicketSetting(PrintQueue printQueue) { PrintCapabilities printCapabilities = printQueue.GetPrintCapabilities(); if(printCapabilities.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge)) { PrintTicket printTicket = new PrintTicket(); printTicket.Duplexing = Duplexing.TwoSidedLongEdge; ValidationResult validationResult = printQueue.MergeAndValidatePrintTicket(printQueue.UserPrintTicket, printTicket); if(validationResult.ValidatedPrintTicket.Duplexing == Duplexing.TwoSidedLongEdge) { printQueue.UserPrintTicket = validationResult.ValidatedPrintTicket; printQueue.Commit(); Console.WriteLine("PrintTicket new duplexing setting is set on '{0}'.", printQueue.FullName); } else { Console.WriteLine("PrintTicket new duplexing setting is constrained on '{0}'.", printQueue.FullName); } } else { Console.WriteLine("PrintTicket new duplexing setting is not supported on '{0}'.", printQueue.FullName); } } #endregion #region 프로그램 시작하기 - Main(argumentArray) /// <summary> /// 프로그램 시작하기 /// </summary> /// <param name="argumentArray">인자 배열</param> [STAThread] private static void Main(string[] argumentArray) { try { if((argumentArray.Length == 1) && (argumentArray[0] == "-a")) { LocalPrintServer localPrintServer = new LocalPrintServer(); EnumeratedPrintQueueTypes[] enumeratedPrintQueueTypesArray = { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections }; foreach(PrintQueue printQueue in localPrintServer.GetPrintQueues(enumeratedPrintQueueTypesArray)) { ChangePrintTicketSetting(printQueue); } } else if((argumentArray.Length == 2) && (argumentArray[0] == "-l")) { LocalPrintServer localPrintServer = new LocalPrintServer(); PrintQueue printQueue = new PrintQueue(localPrintServer, argumentArray[1]); ChangePrintTicketSetting(printQueue); } else if((argumentArray.Length == 2) && (argumentArray[0] == "-r")) { string serverName = argumentArray[1].Remove(argumentArray[1].LastIndexOf(@"\")); string printerName = argumentArray[1].Remove(0, argumentArray[1].LastIndexOf(@"\") + 1); PrintServer printServer = new PrintServer(serverName); PrintQueue printQueue = new PrintQueue(printServer, printerName); ChangePrintTicketSetting(printQueue); } else { DisplayUsage(); } } catch(Exception exception) { Console.WriteLine(exception.Message); Console.WriteLine(exception.StackTrace); if(exception.InnerException != null) { Console.WriteLine("--- Inner Exception ---"); Console.WriteLine(exception.InnerException.Message); Console.WriteLine(exception.InnerException.StackTrace); } } finally { Console.WriteLine("Press Return to continue..."); Console.ReadLine(); } } #endregion } } |