Search code examples
c++winapiprintinggdi

WINAPI Print - Two paper types with same dimensions


I am having with a problem printing using WINAPI. There is this printer, DS40, and this printer provides two different "paper sizes" (6x4", 6x4"x2), which have exactly same dimensions, but each does something little different (reasons behind this are rather difficult to explain, I think it is not necessary to do so here).

For printing, I am using the Qt Framework, which is using the GDI Print API. However, it does not matter which paper variant I choose, it always uses the same one.

When looking into Qt's source code, I found out that it is passing the paper size through this structure: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183565%28v=vs.85%29.aspx, namely members dmPaperWidth and dmPaperLength.

Now, how can I differentiate between those two paper size variants?


Solution

  • As stated in documentation for DEVMODE structure:

    dmPaperWidth/dmPaperLength override dmPaperSize

    To select a specific dmPaperSize (for example A4, Letter, Legal, etc.) use the following settings:

    • dmFields |= DM_PAPERSIZE
    • dmPaperSize = papersize_index

    • Don't use DM_PAPERWIDTH and DM_PAPERLENGTH in dmFields flag

    You can use DeviceCapabilities and DC_PAPERNAMES to get a list of paper sizes which are supported by current printer.