Issues with Custom Page Size on OKI MICROLINE 8480FB Using Windows API and C++
I'm working with the Windows API in C++ to set a custom page size for a dot-matrix printer (OKI MICROLINE 8480FB). I successfully configured the page size to 16 inches in width and 21 inches in height. Using this setup, I can print content at the Y-coordinate of 20 inches without any issues.
However, when I attempt to increase the page height beyond 21 inches, the printer stops working altogether. The program doesn’t throw any errors, but the printer fails to respond or print anything.
This is my example code running on Window11.
#define UNICODE
#include <windows.h>
#include <iostream>
int main() {
// Specify the printer name
const WCHAR* printerName = L"OKI MICROLINE 8480FB";
const WCHAR* printerJob = L"Custom Print Job";
const WCHAR* parameter1 = L"WINSPOOL";
// Initialize the DEVMODE structure to customize the printer settings
DEVMODE devMode = { 0 };
devMode.dmSize = sizeof(DEVMODE);
devMode.dmFields = DM_PAPERSIZE | DM_PAPERWIDTH | DM_PAPERLENGTH;
devMode.dmPaperWidth = 4060; // Custom width in tenths of a millimeter (16 inches)
devMode.dmPaperLength = 5334; // Custom height in tenths of a millimeter (21 inches), any attempts to set height to a higher value will fail
// Create a device context for the printer
HDC hdc = CreateDC(parameter1, printerName, NULL, &devMode);
if (!hdc) {
std::cerr << "Failed to create printer device context.\n";
return 1;
}
// Begin a print job
DOCINFO docInfo = { sizeof(DOCINFO), printerJob, NULL };
if (StartDoc(hdc, &docInfo) <= 0) {
std::cerr << "Failed to start the print job.\n";
DeleteDC(hdc);
return 1;
}
// Start a page
if (StartPage(hdc) <= 0) {
std::cerr << "Failed to start a page.\n";
EndDoc(hdc);
DeleteDC(hdc);
return 1;
}
// Draw text at a specific position with Y = 20 inches (in logical units)
const WCHAR* text = L"value";
TextOut(hdc, 100, 3600, text, 5);
// End the page
EndPage(hdc);
// End the print job
EndDoc(hdc);
// Clean up
DeleteDC(hdc);
std::cout << "Printing completed successfully.\n";
return 0;
}
Steps Taken So Far:
- Set custom page size (e.g., width: 16 inches, height: 22 inches or more) in the printer settings via C++.
- Sent print commands to the printer (same commands that work for a 21-inch height).
- Observed that the printer doesn’t print anything, and no errors are returned by the program.
Additional Info:
- Programming language: C++
- Printer model: OKI MICROLINE 8480FB
- The printer handles 16x21-inch page sizes correctly but fails when increasing the height beyond 21 inches.
- I’m not sure if this is a limitation of the printer, a configuration issue, or something I missed in the Windows API implementation.
Questions:
- Are there specific settings, driver configurations, or additional API calls I need to adjust for the printer to accept larger page sizes?
- Could this issue be specific to the Windows API or printer driver when working with C++?
Any guidance or suggestions would be greatly appreciated!