[jcifs] Sending data to printer using jCIFS

Marcus Ilgner marcus.ilgner at gmail.com
Wed Mar 2 11:10:15 MST 2011


On Wed, Mar 2, 2011 at 12:32 PM, 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(\\\\10.88.183.236\\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
>

Hi Naveen,

it has been some time since I used this feature but there is a patch
originally by Adobe to support this which I once adapted to work with
JCIFS 1.3.14.
Maybe you'll have to make some more changes to get it to patch a
current version, but you should give it a try.
You can find it here:
http://jcifs.samba.org/src/patches/jcifs_1.3.14-printing.patch

Best regards
Marcus


More information about the jCIFS mailing list