Skip to content

harwey/cups4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

248 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Maven Central Version

Cups4j

Cups4j — the Java printing library for CUPS.

Table of Contents

Importing

This library is available on the Maven Central repository, here.
To import and use cups4j in your project, add the following dependency in your pom.xml file:

<dependency>
    <groupId>org.cups4j</groupId>
    <artifactId>cups4j</artifactId>
    <version>0.8.1</version>
</dependency>

Usage

Basic usage

CupsClient cupsClient = new CupsClient();
CupsPrinter cupsPrinter = cupsClient.getDefaultPrinter();
InputStream inputStream = new FileInputStream("test-file.pdf");
PrintJob printJob = new PrintJob.Builder(inputStream).build();
PrintRequestResult printRequestResult = cupsPrinter.print(printJob);

Connect to custom host

CupsClient cupsClient = new CupsClient(URI.create("http://127.0.0.1:631"));

Get specific printer by URL

URI printerURL = new URI("http://127.0.0.1:631/printers/printer-name");
CupsPrinter cupsPrinter = cupsClient.getPrinter(printerURL);

Add extra PrintJob attributes

PrintJob printJob = new PrintJob.Builder(bytes)
                                .jobName("job-name")
                                .userName("user-name")
                                .copies(2)
                                .pageRanges("1-3")
                                .duplex(false)
                                .portrait(false)
                                .color(true)
                                .pageFormat("iso-a4")
                                .resolution("300dpi")
                                // extra PrintJob attributes
                                .attribute("compression", "none")
                                .attribute("job-attributes", "print-quality:enum:3#fit-to-page:boolean:true#sheet-collate:keyword:collated")
                                .build();

More Infos

About

Cups4j Java printing library for CUPS/IPP

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors