package cc.dowell.hwp.utils;
import org.cups4j.CupsClient;
import org.cups4j.CupsPrinter;
import org.cups4j.PrintJob;
import org.cups4j.PrintRequestResult;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
public class PrintByCups {
public static void toPrint(String args) throws Exception {
CupsClient cupsClient = new CupsClient("192.168.31.31", 631);
CupsPrinter cupsPrinter = cupsClient.getDefaultPrinter();
String msg = args;
InputStream is = PrintByCups.class.getClassLoader().getResourceAsStream("word_test.docx");
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(is)
.jobName("job-name")
.userName("user-name")
.copies(1)
.duplex(false)
.portrait(true)
.color(false)
.pageFormat("iso-a4")
.attributes(attributes)
.build();
PrintRequestResult printRequestResult = cupsPrinter.print(printJob);
}
public static void main(String[] args) throws Exception {
PrintByCups.toPrint("abcdefg");
}
}

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46