Our web application has a flow where in the on click of print button on a page, raw data from the server is printed on the client's machine on a user selected printer (Zebra label printer). Following sequence of interactions are involved between the browser and the server:
1)User clicks on print on a page
2)Server sends back an applet
3)This applet makes url connection to the server to retrieve the print data
4)The applet then looks up the list of printers installed on the client's machine and shows the printer selection dialog. All the printer lookup is done using javax.print
5)Once the user selects the label printer, the applet creates a print job and sends it to the selected printer. The label gets printed
Now since google has removed NPAPI from chrome, we were looking at what alternatives do we have to get the same functionality on chrome and specifically on windows. Initially going though Google native client docs, we thought that we could realize the above use case using PNACL. Following code is from MSDN which is routine for printing raw data to the default printer using winspool.h
BOOL RawDataToPrinter(LPBYTE lpData, DWORD dwCount) {
HANDLE hPrinter;
DOC_INFO_1 DocInfo;
DWORD dwJob;
DWORD dwBytesWritten;
TCHAR result[ MAX_PATH ] = {'\0'};
DWORD length = MAX_PATH;
GetDefaultPrinter( result, &length );
// Need a handle to the printer.
if( ! OpenPrinter(result, &hPrinter, NULL ) )
return FALSE;
// Fill in the structure with info about this "document."
DocInfo.pDocName = L"Demo Page";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = L"RAW";
// Inform the spooler the document is beginning.
if( (dwJob = StartDocPrinter( hPrinter, 1, (BYTE *)&DocInfo )) == 0 )
{
ClosePrinter( hPrinter );
return FALSE;
}
// Start a page.
if( ! StartPagePrinter( hPrinter ) )
{
EndDocPrinter( hPrinter );
ClosePrinter( hPrinter );
return FALSE;
}
// Send the data to the printer.
if( !WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten ) )
{
EndPagePrinter( hPrinter );
EndDocPrinter( hPrinter );
ClosePrinter( hPrinter );
return FALSE;
}
// End the page.
if( ! EndPagePrinter( hPrinter ) )
{
EndDocPrinter( hPrinter );
ClosePrinter( hPrinter );
return FALSE;
}
// Inform the spooler that the document is ending.
if( ! EndDocPrinter( hPrinter ) )
{
ClosePrinter( hPrinter );
return FALSE;
}
// Tidy up the printer handle.
ClosePrinter( hPrinter );
// Check to see if correct number of bytes were written.
if( dwBytesWritten != dwCount )
return FALSE;
return TRUE;
}
Initially we thought that we would be able to call the above routine from a pepper plugin. The javascript on page would retreive the label data and pass it to the native client instance, and this would call the RawDataToPrinter(..) routine.
However from what we understood from the forums out here is that Native client won't be able to access/lookup the printers and spool the raw data to the selected printer.it wont allow you to call anything outside the api ports that they provide
Is this understanding correct? If yes then is there any alternative to realize the above mentioned use case on chrome? if no and the above is possible, are there any available ports which allow access to printers installed on client's machine and allow us to print the data to the selected printer?