There are two worlds in the windows priting system.
One is the metric/unit system in the GDI system, in which visuals, text, pictures are managed, manipulated, transformed in memory and rendered by the Video card.
With advent of WPF, a device independant visual system is unified. with this system, unit/metrics are measure in terms of physical unit, such as inch, millimeter.... The namespace which is related to printing in WPF world is System.Drawing.Printing;
While the other system is the printer device system, on which resolution, quality, fidelity varies across device to device. On this system, it is more often used that the system of pixels. The namespace is System.Printing;
So given a PageMediaSize (from System.Printing), and PaperSize (from System.Drawing.Printing), there is no wonder that you may do the following transformation if you want to find a match PaperSize for a given PagemediaSize.
//@Comment: find a matching PageSize given a list of PageSize and one System.Drawing.Print.PageMediaSize //PrintQueue.UserTicket.PageMediaSize --> PaperSize -- consumed by --> VisualPaginator //@param rotated: this is set to true if the PaperSize returned is a rotated one of the param pagemediaSize; public static PaperSize FindMatchingPageMediaSize(PageMediaSize pageMediaSize, IList<PaperSize> paperSizes, out bool rotated) { if (pageMediaSize == null) throw new ArgumentNullException("pageMediaSize"); if (paperSizes == null) throw new ArgumentNullException("paperSizes"); rotated = false; var widthInInch = Math.Round(pageMediaSize.Width.Value / 96 * 100); var heightInInch = Math.Round(pageMediaSize.Height.Value / 96 * 100); var paperSize = paperSizes.FirstOrDefault(p => p.Width == widthInInch && p.Height == heightInInch); if (paperSize == null) { paperSize = paperSizes.FirstOrDefault(p => p.Width == heightInInch && p.Height == widthInInch); if (paperSize != null) rotated = true; } if (paperSize != null) return paperSize; return null; }
You may wonder why there is 96 in the code, it is just the DPI value that is standard in WPF or Printing?. Dived by 96 then multiple 100 will give you the width that Device Indepedant width (screen width) in WPF.
there is a good reading on the blog about "Where does 96 DPI come from in Windows?"
Glossary/Acronyms
DPI: Dots per inch
PPI: Pixels per inch