[jcifs] Sending data to printer using jCIFS

Michael B Allen ioplex at gmail.com
Sat Mar 5 17:09:58 MST 2011

Hi Naveen,

If I recall correctly, there are some flags in some messages that need
to be a little different for writing to a printer. Search the
archives. I think the flags in question have been discussed
previously. If you identify the correct flags, you may be able to
extend some class and set them as necessary.

Note that in general, writing raw data to a printer from CIFS is a
dubious practice. There could be a huge variation of results with
different printers. The Samba people call this "printer hell".


On Wed, Mar 2, 2011 at 6:32 AM, Naveen Maheshwari <naveenmah at gmail.com> wrote:
> Hi!
> This questions has been asked many times but i could not find any reply
> anywhere
> I want to send raw data lets say a pcl file to a shared printer on windows.
> When I do SmbFile[] files = file.listFiles();
> I discover my printer properly, there is no issue
> To send the data to the printer i am doing this
>        byte[] buf = new byte[1024];
>        //test.prn is just any prn file.
>        String root = "d:\\test.prn";
>        FileInputStream fin = new FileInputStream(new File(root));
>        // Always get exception here Parameter incorrect
>        SmbFileOutputStream fos = new SmbFileOutputStream(printer);
>        int len;
>        while ((len = fin.read(buf)) > 0){
>          fos.write(buf,0,len);
>        }
>        fin.close();
>        fos.close();
> where printer is the smbfile of printer i got from listFiles();
> I always get exception at parameter incorrect
> at SmbFileOutputStream(printer) .
> If instead of SmbFileOutputStream() i use
> FileOutputStream fos = new FileOutputStream(\\\\\\myPrinter);
> PrintStream ps = new PrintStream(fos);
> it works fine on windows machine , but i can not use this as I need to print
> from android.
> Pls. advice what I am doing wrong?
> Thanks

Michael B Allen
Java Active Directory Integration

More information about the jCIFS mailing list