[jcifs] Printing

Michael B.Allen mballen at erols.com
Wed May 15 06:03:06 EST 2002

On Tue, 14 May 2002 15:58:04 +0300
Ykä Huhtala <Yka.Huhtala at cdgroup.fi> wrote:

> Hi,
> Is there an example code on how to print to a shared printer. First I wrote
> the following small program:
>     public static void print(String filename, String share)
> 	throws Exception
>     {
> 	try {
> 	    jcifs.Config.setProperty("wins", "");
> 	    PrintWriter out = new PrintWriter(new SmbFileOutputStream(share));
> 	    FileReader in = new FileReader(filename);
> 	    int c;
> 	    while ((c = in.read()) != -1) {
> 		out.write(c);
> 	    }
> 	    out.close();
> 	} catch(Exception e) {e.printStackTrace();}
>     }
> Next, I tried printing using the Put program under the example files, but
> unfortunately it also failed. As a result in both cases, I get an Invalid
> parameter exception:
> Exception in thread "main" jcifs.smb.SmbException: Invalid parameter
> 	at jcifs.smb.SmbTransport.send(SmbTransport.java:495)
> 	at jcifs.smb.SmbSession.send(SmbSession.java:135)
> 	at jcifs.smb.SmbTree.send(SmbTree.java:91)
> 	at jcifs.smb.SmbFile.send(SmbFile.java:499)
> 	at jcifs.smb.SmbFile.open(SmbFile.java:555)
> 	at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:107)
> 	at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:92)
> 	at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:62)
> 	at Put.main(Put.java:30)

Printing is a little bit of a different story. I haven't really looked
at it. The main thing is that it just isn't that attractive because
there is no way to obtain PostScript or other output from within the
JVM. This limits jCIFS printing usefullness (e.g. you cannot print the
screen or the text of an HTML UI component). It could only be used as
transport. It might be usefull to a print filter but they might as well
just use smbprint from Samba for that.

Even if it worked, what do you intend to print? Are you going to generate
PostScript yourself? Plain ASCII doesn't make for very nice printouts.

Eventually I will figure out how to get it to work. Probably not hard


> Printing works fine, for example, with Samba smbclient's print command. The
> share URL that I'm trying to use is
> smb://user:password@server/Printer
> where Printer is share name of the printer at the server. Any ideas?
> Cheers, Yka

May The Source be with you.

More information about the jcifs mailing list