Pages per sheet RRS feed

  • Question

  • Hello!

    Unidrv printer settings dialog has option "Pages Per Sheet" and I wonder to know, how to get this value. I've tried to load unidrvui.dll, get address of "DrvQueryJobAttributes" and call this method, but it always returns dwJobNumberOfPagesPerSide == 1. By the way, printer settings dialog store this value correctly. How to obtain this value?

    Tuesday, October 14, 2014 10:39 AM

All replies

  • Hi there,

    Your best bet is to read the PrintTicket. IF you've got a DEVMODE, you can call PTConvertDevModeToPrintTicket, and then parse the PrintTicket for the DocumentNup or JobNUpAllDocumentsContiguously Features. The PrintSchema specification has information on how the PrintTicket is formatted.



    Tuesday, October 14, 2014 10:26 PM
  • Thank you for reply!

    So, I've tried your way but PTConvertDevModeToPrintTicket return ERROR_INVALID_DATA. My source code below

      vpd::Devmode devmode(PRINTER_NAME); // get DEVMODE via GetPrinter() and PRINTER_INFO_2
      if (!devmode){
        ERROR_LOG("Converter::getNupSettings(): failed to vpd::Devmode().", GetLastError(), __LINE__, __FILE__);
        return false;
      HRESULT result = S_OK;
      Provider provider(nullptr); // RAII wrapper for HPTPROVIDER
      result = PTOpenProvider(PRINTER_NAME, 1, &provider);
      if (FAILED(result)){
        ERROR_LOG("Converter::getNupSettings(): failed to PTOpenProvider().", GetLastError(), __LINE__, __FILE__);
        return false;
      IStream *stream = nullptr;
      result = CreateStreamOnHGlobal(nullptr, TRUE, &stream);
      if (FAILED(result)){
        ERROR_LOG("Converter::getNupSettings(): failed to CreateStreamOnHGlobal().", GetLastError(), __LINE__, __FILE__);
        return false;
      ULONG cbDevmode = sizeof(DEVMODE);
      result = PTConvertDevModeToPrintTicket(provider, cbDevmode, devmode, kPTJobScope, stream);
      if (FAILED(result)){ // Always returns ERROR_INVALID_DATA
        ERROR_LOG("Converter::getNupSettings(): failed to PTConverteDevModeToPrintTicket().", GetLastError(), __LINE__, __FILE__);
        return false;
    Wednesday, October 15, 2014 8:33 AM