简体   繁体   中英

Null values for PageMediaSize of a PrintTicket with Adobe PDF Creator using custom page size

I'm writing a WPF application to get and save print profiles (and another application using this print profiles to print documents).

It works fine except when I try to use Adobe PDF Creator has a printer with custom size (like 800mm by 1200mm). Then the PageMediaSize Width and Height are null in the print ticket.

Here's the code I use to get the PrintTicket :

        PrintDialog pd = new PrintDialog();
        if (pd.ShowDialog() == true)
        {
            PrintDocument doc = new PrintDocument();
            doc.PrintPage += (o, a) =>
            {
                PrintQueue pq = pd.PrintQueue;
                PrintTicket ticket = pd.PrintTicket;
                ...
                a.Cancel = true;
            };
            doc.Print();
        }

The PrindDialog contains the correct width and height for the page, but if I try to use the PrintTicket to print a document it crash, stating that PageMediaSize cannot contains null values.

Anyone have an idea on how to get a working PrintTicket ?

It sounds like a problem with Adobe PDF Creator's driver. The driver provides values for all the sizes, so if there is a problem, you might want to contact the makers of the printer/driver.

A way around this would be to figure out the sizes (800mm x 1200mm) and assume a resolution of 1/96 inches. Then do a conversion:

Width:  ( 800mm) / (25.4 mm/in) / (1/96in) = 3023.62
Height: (1200mm) / (25.4 mm/in) / (1/96in) = 4535.43

And with those values you can say:

pd.PrintTicket.PageMediaSize = new PageMediaSize(Width, Height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM