2

I'm trying to send a PDF/DOC/ODT file to a printer connected in LAN using javax.print, but it doesn't even send the job to the print queue. I've tried to print the file "normally" (using Adobe Reader /Open Office) and works perfectly, so the printer is well connected. I've also tried to send it to a virtual printer (PDFCreator) from code and it worked.

Here is the code I'm using:

public Boolean Imprimir (String filePath){
    Boolean correct = true;

    FileInputStream psStream = null;  
    try {  
        psStream = new FileInputStream(filePath);  
    } catch (FileNotFoundException ex) {  
        ex.printStackTrace();
        correct = false;
    }
    if (psStream != null) {  

        DocFlavor psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;  
        Doc myDoc = new SimpleDoc(psStream, psInFormat, null);    
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();            
        PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);

        PrintService myPrinter = null;  
        for (int i = 0; i < services.length; i++){  
            String svcName = services[i].toString();             

            if (svcName.contains("Xerox")){  
                myPrinter = services[i];                       
                break;  
            }  
        }

        if (myPrinter != null) {              
            DocPrintJob job = myPrinter.createPrintJob();
            try{                    
                job.print(myDoc, aset);  
            }
            catch(PrintException ex){
                ex.printStackTrace();
                correct = false;
            }
        } else {  
            System.out.println("No printer services found");  
            correct = false;
        }
    }
    else{
        correct = false;
    }

    return correct;
}

The printer is connected using LPR protocol.

Thanks in advance

Edit: I've also tried using jLpr, as suggested in other posts (Java printing directly to a Postscript network printer). It didn't work either, no error messages though, the job doesn't appear in the printer's queue.

Community
  • 1
  • 1
Joel
  • 193
  • 1
  • 6
  • 12
  • I've found that the problem may be that the printer is connected using the LPR protocol. I tried sending the print job to a printer connected with RAW protocol and it worked fine. I'll leave the question unanswered because I still don't know how to deal with LPR protocol. – Joel Nov 23 '12 at 16:56
  • Did you solve your issue? Would you mind sharing the solution, if any? Thanks – Benoit Duffez Apr 23 '14 at 15:29

1 Answers1

-2

What Adobe Reader version do you use?. Could be a Adobe Reader security issue, depending on its version.

Regards

ospaco69
  • 9
  • 4