0

I using this library for printing, and I am using Ubuntu.

My code is the following:

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

However I am not able to print. When I use

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

the text is getting printed in hi.txt file.

I tried \dev\lpr but it is giving me error

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

Here is my full source code

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();
}

Please help me.

4

1 回答 1

1

你需要先编辑一些权限,试试这个

编辑/etc/cups/cupsd.conf中的文件

搜索lpadmin并将其更改为lp

于 2012-05-18T23:04:29.437 回答