Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print "raw" data using Print Spooler API

Tags:

c++

printing

I'm using windows spooler API in order to print a simple picture. In "TEXT" mode, my printer prints the picture as a text like it converts its data to char. So I've to use the "RAW" mode but nothing append in this case.
Here is the code :

void camgl::printShoot() {
HANDLE print_handle;
DOC_INFO_1 docinfo1;
DWORD bytes_written;

docinfo1.pDocName = (LPTSTR)L"Shot.jpg";
docinfo1.pOutputFile = NULL;
docinfo1.pDatatype = (LPTSTR)L"RAW";

BOOL bool1, bool2, bool3, bool4;

bool1 = OpenPrinter((LPTSTR)L"Canon MG6300 series Printer", &print_handle, NULL);
bool2 = StartDocPrinter(print_handle, 1, (LPBYTE)&docinfo1);

bool3 = StartPagePrinter(print_handle);
bool4 = WritePrinter(print_handle, (LPVOID)image->imageData, (DWORD)image->imageSize, &bytes_written);
EndPagePrinter(print_handle);
EndDocPrinter(print_handle);

ClosePrinter(print_handle); 
}

The variable "image" is defined like this :

  • IplImage *image;

where IplImage is an OpenCV type of image.

I've tried to send a form-feed character to the printer but with no success:

int iFF = 0x0c;
WritePrinter(print_handle, (LPVOID)&iFF, (DWORD)sizeof(iFF), &bytes_written);

In both cases, the print queue displays a job that correspond to the printShoot() method, then the queue is cleared with no error and nothing is print by the printer.

==============

I add this article i've just found :
http://www.codeproject.com/Articles/8916/Printing-Architecture


1 Answers

WritePrinter only supports GDI printing.

Printing JPEG image requires more code. IF it is urgent, you can try to call Command line MS Paint to print the JPEG image

C:\Windows\System32\mspaint.exe C:\image.jpg /p
like image 109
Tony Avatar answered Apr 19 '26 16:04

Tony