how do I set Paper Type while using PrinterDialog?

后端 未结 2 646
心在旅途
心在旅途 2021-02-06 19:08

I\'m trying to silently print a picture file and i need to print it on special paper type (\"Glossy Photo Paper\"), and on certain size (10cm on 15cm).

On normal windows

2条回答
  •  半阙折子戏
    2021-02-06 19:32

    This can actually be done without DEVMODE. Set the paper type via PrintTicket.PageMediaType property. For example:

        // ---------------------- GetPrintTicketFromPrinter ----------------------- 
        ///  
        ///   Returns a PrintTicket based on the current default printer. 
        ///  
        ///   A PrintTicket for the current local default printer. 
        public PrintTicket GetPrintTicketFromPrinter()
        {
            PrintQueue printQueue = null;
    
            var localPrintServer = new LocalPrintServer();
    
            // Retrieving collection of local printer on user machine
            PrintQueueCollection localPrinterCollection = localPrintServer.GetPrintQueues();
    
            System.Collections.IEnumerator localPrinterEnumerator =
                localPrinterCollection.GetEnumerator();
    
            if (localPrinterEnumerator.MoveNext())
            {
                // Get PrintQueue from first available printer
                printQueue = (PrintQueue)localPrinterEnumerator.Current;
            }
            else
            {
                // No printer exist, return null PrintTicket 
                return null;
            }
    
            // Get default PrintTicket from printer
            PrintTicket printTicket = printQueue.DefaultPrintTicket;
    
            PrintCapabilities printCapabilites = printQueue.GetPrintCapabilities();
    
            // Modify PrintTicket 
            if (printCapabilites.PageMediaTypeCapability.Contains(PageMediaType.CardStock))
            {
                printTicket.PageMediaType = PageMediaType.CardStock;
            }
    
            return printTicket;
        }
    

提交回复
热议问题