'Print "raw" data using Print Spooler API

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



Solution 1:[1]

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

Solution 2:[2]

I've found a solution by using XPS API like described there :
http://msdn.microsoft.com/en-us/library/windows/desktop/ff728890(v=vs.85).aspx

And a sample code is available there :
http://msdn.microsoft.com/en-us/library/windows/desktop/ee236514(v=vs.85).aspx

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2