how do I set Paper Type while using PrinterDialog?

限于喜欢 提交于 2019-12-03 05:06:36
user957902

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

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;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!