Cups4J.org

The Cups4J user Forum
It is currently Thu Mar 23, 2017 3:08 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: ipp printer
PostPosted: Tue Apr 08, 2014 7:26 am 
Offline

Joined: Mon Apr 07, 2014 4:57 pm
Posts: 5
Good morning everybody, I am trying to use cups4j to send print jobs to an ipp printer accessible via a url like ipp://ips4/printers/.... Is it possible to have an example ? I am trying to run the following code

Code:
CupsPrinter printer = client.getPrinter(new URL("ipp://ps01/printers/port1"));
PrintJob printJob = new PrintJob.Builder(new FileInputStream("/Users/fabio/cust/report_1-02-04-2014_1152.pdf")).build();
printer.print(printJob);


but when creating the cupsPrinter an exception is thrown saying that the protocol is not recognized.

Any idea to solve this problem ?

Thanks

Fabio


Top
 Profile  
 
 Post subject: Re: ipp printer
PostPosted: Tue Apr 08, 2014 7:44 am 
Offline

Joined: Wed Jan 05, 2011 9:44 pm
Posts: 44
Location: Germany
Hi Fabio,

welcome on board.

Cups4J uses HTTP to communicate with CUPS servers, so your URL probably should look like this:
Code:
new URL("http://ps01:631/printers/port1")

To find your printer URLs try to run this code. Afterwards try your code again with the found printer URLs.

Make sure to change hostname and port according to your CUPS server configuration.

Code:
    List<CupsPrinter> printers = null;
   
      try {
        String hostname = "your host";
        int port = 631;
   
        CupsClient cupsClient = new CupsClient(hostname, port);
        printers = cupsClient.getPrinters();
        for (CupsPrinter p : printers) {
           System.out.println(p.toString());
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
   


Harald


Top
 Profile  
 
 Post subject: Re: ipp printer
PostPosted: Tue Apr 08, 2014 8:03 am 
Offline

Joined: Mon Apr 07, 2014 4:57 pm
Posts: 5
Hi Harald, thanks for your reply. Actually the printer is available at the url

ipp://ps01/printers/port1

I manage to connect to it with ipptool. I tried your code but it doesn't seem to accept connection through http on the port 631. It is not possible to use cups4j to connect using ipp instead of http ?

Thaks

Regards

Fabio


Top
 Profile  
 
 Post subject: Re: ipp printer
PostPosted: Tue Apr 08, 2014 8:14 am 
Offline

Joined: Wed Jan 05, 2011 9:44 pm
Posts: 44
Location: Germany
Hi Fabio,

IPP is a protocol that works on top of HTTP. In order to communicate with CUPS servers you need to use HTTP. That's what Cups4J does.
If I understand correctly, you want to talk to an IPP enabled printer directly without any CUPS server right?

This should also work wiht the code base of Cups4J but probably you need to dig in the code and make some changes according to the URL changed from IPP:... to HTTP:....

On the bottom of IppOperation.java you could prevent the change to http URL and try again with your code posted in the first place.

protected String stripPortNumber(URL url) {
String protocol = url.getProtocol();
if ("ipp".equals(protocol)) {
protocol = "http";
}

return protocol + "://" + url.getHost() + url.getPath();
}


Harald


Top
 Profile  
 
 Post subject: Re: ipp printer
PostPosted: Wed Apr 09, 2014 4:12 pm 
Offline

Joined: Mon Apr 07, 2014 4:57 pm
Posts: 5
Hi, thanks for your Help, I finally managed to print by configuring properly the cups server. However I have another problem. I don't manage to get the printer to print from the lower tray. I use the following code
Code:
 
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("job-attributes", "media:keyword:Lower" );
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("job-attributes", "media:keyword:Lower" );
PrintJob printJob = new PrintJob.Builder(new FileInputStream("/Users/fabio/cust/report_1-02-04-2014_1152.pdf")).attributes(attributes).build();
 printer.print(printJob);


I downloaded the swing app and run it, under supported media I found :

media-supported ---- keyword----- Upper
media-supported ---- keyword----- Lower

so, do you have any idea of where my code is wrong ?

Thanks

Fabio


Top
 Profile  
 
 Post subject: Re: ipp printer
PostPosted: Wed Apr 09, 2014 4:13 pm 
Offline

Joined: Mon Apr 07, 2014 4:57 pm
Posts: 5
sorry, wrong copy paste, this is the correct code

Code:
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("job-attributes", "media:keyword:Lower" );
PrintJob printJob = new PrintJob.Builder(new FileInputStream("/Users/fabio/cust/report_1-02-04-2014_1152.pdf")).attributes(attributes).build();
 printer.print(printJob);



Thanks

Fabio


Top
 Profile  
 
 Post subject: Re: ipp printer
PostPosted: Wed Apr 09, 2014 4:40 pm 
Offline

Joined: Wed Jan 05, 2011 9:44 pm
Posts: 44
Location: Germany
Hi Fabio,

good to hear that printing works for you. Also your code to set the media attribute seems correct. Please set LogLevel debug2 in your cupsd.conf and take a look in the CUPS server log. Probably something does not work there and gets reported.

Come back to this thread if you don't get it to work
Harald


Top
 Profile  
 
 Post subject: Re: ipp printer
PostPosted: Wed Apr 09, 2014 5:23 pm 
Offline

Joined: Mon Apr 07, 2014 4:57 pm
Posts: 5
Ok, it works, the problem is just that if i say lower, it takes the upper tray and viceversa... so, it's ok once you know it!!

Just the last question: what if my printer has 3 trays (it's actually the case) and I have to select the tray in the middle ? Is this option supported ?

Thanks

Fabio


Top
 Profile  
 
 Post subject: Re: ipp printer
PostPosted: Wed Apr 09, 2014 5:57 pm 
Offline

Joined: Wed Jan 05, 2011 9:44 pm
Posts: 44
Location: Germany
All attributes supported via CUPS should be reported by my swing app. If it is supported by CUPS you can adress it with Cups4J. If not its a driver issue within CUPS. You could try to print on your third tray from f.ex. OpenOffice and just check your CUPS server logs and probably find some attribute name that also works from Cups4J. If you like to investigate this, just give it a try.

Harald

fabio_fornelli wrote:
Ok, it works, the problem is just that if i say lower, it takes the upper tray and viceversa... so, it's ok once you know it!!

Just the last question: what if my printer has 3 trays (it's actually the case) and I have to select the tray in the middle ? Is this option supported ?

Thanks

Fabio


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group