2011-06-23 19 views
0

我使用this library進行打印,而且我使用的是Ubuntu。在Ubuntu中使用textPrinter打印

我的代碼如下:

FilePort port=new FilePort("\\\\printerIp:631\\printers\\Hewlett-Packard-HP-LaserJet-Professional-P1606dn"); 
TextPrinter printer=PrinterFactory.getPrinter("HP-PCL5"); 

但是我不能打印。當我使用

FilePort port=new FilePort("\home\hi.txt")

是越來越印在hi.txt文件中的文本。

我試圖\dev\lpr,但它給我錯誤

com.java4less.textprinter.exceptions.CouldNotOpenPrinterException: /dev/lpr (Permission denied) 
FilePort port=new FilePort("\dev\lpr"); 

這裏是我的全部源代碼

try { 

    FilePort port = new FilePort("\\\\10.9.42.136:631\\printers\\Hewlett-Packard-HP-LaserJet-Professional-P1606dn"); 
    // get printer supporting HP-PCL command set 
    TextPrinter printer = PrinterFactory.getPrinter("HP-PCL5"); 

    // create printing job 
    JobProperties job = printer.getDefaultJobProperties(); 
    job.landscape = true; 
    printer.startJob(port, job); 

    // print BOLD text 
    TextProperties prop = printer.getDefaultTextProperties(); 
    prop.bold = true; 
    printer.printString("This must be BOLD", prop); 
    printer.newLine(); 
    printer.newLine(); 
    printer.printString("Hello world..", prop); 
    // print line 
    printer.printHorizontalLine(5,0,80);   // row 5, column 0 to 80 

    printer.endJob(); 

} catch (Exception e) { 
    e.printStackTrace(); 
} 

請幫助我。

回答

1

您需要先編輯一些權限,試試這個

編輯在文件/etc/cups/cupsd.conf中

搜索的lpadmin並將其更改爲LP

相關問題