If the printer supports PostScript directly, you can buffer the original print jobs as follows:
HANDLE ph; OpenPrinter(&ph, "Printer Name", NULL); di1.pDatatype = IsV4Driver("Printer Name") ? "XPS_PASS" : "RAW"; di1.pDocName = "Raw print document"; di1.pOutputFile = NULL; StartDocPrinter(ph, 1, (LPBYTE)&di1); StartPagePrinter(ph); WritePrinter(ph, buffer, dwRead, &dwWritten); EndPagePrinter(ph); EndDocPrinter(ph)
Repeat WritePrinter until you have wound the whole file.
IsV4Driver () Checks for drivers of version 4, this is necessary in Windows 8 and Server 2012:
bool IsV4Driver(wchar_t* printerName) { HANDLE handle; PRINTER_DEFAULTS defaults; defaults.DesiredAccess = PRINTER_ACCESS_USE; defaults.pDatatype = L"RAW"; defaults.pDevMode = NULL; if (::OpenPrinter(printerName, &handle, &defaults) == 0) { return false; } DWORD version = GetVersion(handle); ClosePrinter(handle); return version == 4; } DWORD GetVersion(HANDLE handle) { DWORD needed; GetPrinterDriver(handle, NULL, 2, NULL, 0, &needed); std::vector<char> buffer(needed); return ((DRIVER_INFO_2*) &buffer[0])->cVersion; }
source share