Hey guys,
im am trying do send a pdf file to a multi-functional kyocera network printer (kyocera taskalfa 400ci) in my company. The printer is not shared over the network, but it is included as a local printer (kyocera printer driver, protocoll is raw, gdi enable) for security reasons. I can print files without any problems on my own.
Now I want to print automatically generated pdf files. I tried different solution for example like printing via adopbe reader but i dont want to use other software.
I found this example to send data directly to a gdi printer:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162959%28v=vs.85%29.aspx[
^]
I used this code:
BOOL RawDataToPrinter(_WSTRING szPrinterName, LPBYTE lpData, DWORD dwCount) {
BOOL bStatus = FALSE;
HANDLE hPrinter = NULL;
DOC_INFO_1 DocInfo;
DWORD dwJob = 0L;
DWORD dwBytesWritten = 0L;
bStatus = OpenPrinter( &szPrinterName[0], &hPrinter, NULL );
if (bStatus) {
DocInfo.pDocName = (LPTSTR)_T("test");
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = (LPTSTR)_T("RAW");
dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo );
if (dwJob > 0) {
bStatus = StartPagePrinter( hPrinter );
if (bStatus) {
bStatus = WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten);
EndPagePrinter (hPrinter);
}
EndDocPrinter( hPrinter );
}
ClosePrinter( hPrinter );
}
if (!bStatus || (dwBytesWritten != dwCount)) {
bStatus = FALSE;
} else {
bStatus = TRUE;
}
return bStatus;
}
long getFileSize(FILE *file) {
long lCurPos, lEndPos;
lCurPos = ftell(file);
fseek(file, 0, 2);
lEndPos = ftell(file);
fseek(file, lCurPos, 0);
return lEndPos;
}
bool sendFile(_WSTRING szFileName, _WSTRING szPrinterName) {
BYTE *fileBuf; FILE *file = NULL;
if ((file = _wfopen(szFileName.c_str(), L"rb")) == NULL)
printf("Could not open specified file \n");
else
printf("File opened successfully \n");
long fileSize = getFileSize(file);
fileBuf = new BYTE[fileSize];
fread(fileBuf, fileSize, 1, file);
if(RawDataToPrinter(szPrinterName, fileBuf, fileSize)) {
wprintf(L"print successfull [%s] \n", szFileName.c_str());
} else {
printf("print not successfull \n");
};
delete[]fileBuf;
fclose(file);
return 0;
}
After every print job i get "print successfull". The printer seems to be find and it can also send data ( bStatus && (dwBytesWritten == dwCount --> TRUE), but nothing will be printed.
Any ideas where i should find the error?
Thanks for your help
Best regards