how do I set Paper Type while using PrinterDialog?

后端 未结 2 607
心在旅途
心在旅途 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:12

    I'm not saying that it is impossible, but its not going to be pretty. Theoretically you can get the DEVMODE structure of the device( that structure will have extensions that are specific to the printer driver) set the correct values, and then write it back. There are some helper functions the the PrinterSettings object to do this. There is an example of doing that here

    0 讨论(0)
  • 2021-02-06 19:32

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

        // ---------------------- GetPrintTicketFromPrinter ----------------------- 
        /// <summary> 
        ///   Returns a PrintTicket based on the current default printer.</summary> 
        /// <returns> 
        ///   A PrintTicket for the current local default printer.</returns> 
        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;
        }
    
    0 讨论(0)
提交回复
热议问题