Code Monkey home page Code Monkey logo

cups4j's Introduction

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.7.6</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("127.0.0.1", 631);

Get specific printer by URL

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

Add extra PrintJob attributes

Map<String, String> attributes = new HashMap<>();
attributes.put("compression", "none");
attributes.put("job-attributes", "print-quality:enum:3#fit-to-page:boolean:true#sheet-collate:keyword:collated");

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")
                                .attributes(attributes)
                                .build();

License

LGPL

cups4j's People

Contributors

harwey avatar oboehm avatar sanmibuh avatar dependabot[bot] avatar glatzan avatar dellgreen avatar neko-gg avatar

Stargazers

divey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.