자바 지정 프린터 인쇄
2126 단어 Java
package com.printer;
import java.io.*;
import java.util.Locale;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
public class PrintTest {
public static void main(String args[]) {
FileInputStream psStream = null;
try {
psStream = new FileInputStream("D:\\work\\ \\ 20121025( ).jpg");
} catch (FileNotFoundException ffne) {
ffne.printStackTrace();
}
if (psStream == null) {
return;
}
// , gif
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.GIF;
//
// DocAttributeSet docAttr = new HashDocAttributeSet();//
// Doc myDoc = new SimpleDoc(psStream, psInFormat, docAttr);
Doc myDoc = new SimpleDoc(psStream, psInFormat, null);
//
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(3));// ,3
//
PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);
// this step is necessary because I have several printers configured
// ,
PrintService myPrinter = null;
for (int i = 0; i < services.length; i++) {
System.out.println("service found: " + services[i]);
String svcName = services[i].toString();
if (svcName.contains("Snagit 11")) {
myPrinter = services[i];
System.out.println("my printer found: " + svcName);
System.out.println("my printer found: " + myPrinter);
break;
}
}
//
AttributeSet att = myPrinter.getAttributes();
for (Attribute a : att.toArray()) {
String attributeName;
String attributeValue;
attributeName = a.getName();
attributeValue = att.get(a.getClass()).toString();
System.out.println(attributeName + " : " + attributeValue);
}
if (myPrinter != null) {
DocPrintJob job = myPrinter.createPrintJob();//
try {
job.print(myDoc, aset);//
} catch (Exception pe) {
pe.printStackTrace();
}
} else {
System.out.println("no printer services found");
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JPA + QueryDSL 계층형 댓글, 대댓글 구현(2)이번엔 전편에 이어서 계층형 댓글, 대댓글을 다시 리팩토링해볼 예정이다. 이전 게시글에서는 계층형 댓글, 대댓글을 구현은 되었지만 N+1 문제가 있었다. 이번에는 그 N+1 문제를 해결해 볼 것이다. 위의 로직은 이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.