Results 1 to 2 of 2
  1. #1
    jpala is offline Member
    Join Date
    Aug 2012
    Rep Power

    Default Printer lookup from Linux for a printer in a Windows machine

    I'm having problems when trying to directly (without any dialog) print a PDF on a Java Web application (on a Websphere Application Server 6.1) and a Java program (both share some code which include this printing code) with a printer. The printer is on a Windows host, and the web application and the non web application are run on Linux.

    I have read that it could be a permission problem, as I would be trying to print with a user in Linux that either doesn't exist on the printing system (Windows) or doesn't have persmissions.

    The server and the Java application are run with user root, so I'm stuck here (if it's a permission problem) as I was told by the client that the user with permissions on the printing server is another one. I know the username that is allowed to print on that server.

    I think it could do it if it's possible to associate Linux's root user with the user on Windows (which has permissions to print) through Samba. But I haven't been able to do it (I'm quite noob in Samba knowledge). Even if I could do this, I'm not sure that it would allow the code to lookup the printer in the Windows machine. I didn't find any method to autheticate or connecting to a server either.

    For further information, I use the class javax.print.PrintServiceLookup in order to looking the printer up, that doesn't seem to have a method to allow me to authenticate on a server or something similar. This is the code:

    Java Code:
        PrinterJob job = PrinterJob.getPrinterJob();
        // Create an array of PrintServices
        AttributeSet aset = new HashAttributeSet();
        aset.add(new PrinterName(pObjImpresora, null));
        aset.add(new RequestingUserName("user",null));
        PrintService[] services = PrintServiceLookup.lookupPrintServices(null,aset);
        if(services.length > 0){
            PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
            printRequestAttributeSet.add(new Copies(1));
            JRPrintServiceExporter exporter;
            exporter = new JRPrintServiceExporter();
            // We set the selected service and pass it as a parameter
            exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[0]);
            exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[0].getAttributes());
            exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
            exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
            exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
    pObjImpresora is a String which has printer's name. I should have a way to reach the server and then the printer on it. I tried this name "\\printserver\MYPRINTER", where "printserver" is the Windows host name, and MYPRINTER is my printer ;)

    Should you have any tips on this, don't hesitate to answer, please. Thanks in advance.
    Last edited by jpala; 08-02-2012 at 03:20 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Printer lookup from Linux for a printer in a Windows machine

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. how to print using shared printer (windows os)
    By robin99 in forum New To Java
    Replies: 0
    Last Post: 04-21-2012, 11:00 AM
  2. Connect to remote Windows machine using JAVA on Linux
    By sumukh_death in forum Networking
    Replies: 6
    Last Post: 09-23-2011, 07:23 PM
  3. Replies: 2
    Last Post: 02-20-2009, 08:25 AM
  4. Specifying a Network Printer in Printer Servlet
    By shapez in forum New To Java
    Replies: 0
    Last Post: 03-06-2008, 04:21 PM
  5. Replies: 0
    Last Post: 08-09-2007, 07:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts