현재이 코드를 사용하고 있지만 던지는 것은 PrintJobFlavorException
입니다. 이것은 내 코드이 하나의 고정 나를 도울 수 있습니다 :String에서 Java로 PDF로 변환하는 방법
public class PJUtil {
public static void main(String[] args) throws Exception {
DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
Writer output = null;
String text = "printing in pdfPrinting in Java ";
File file = new File("C:\\CMPSup_AL_.PDF");
output = new BufferedWriter(new FileWriter(file));
output.write(text);
output.close();
InputStream is = new BufferedInputStream(new FileInputStream(file));
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);
PrintJobWatcher pjDone = new PrintJobWatcher(job);
job.print(doc, null);
pjDone.waitForDone();
is.close();
}
}
및 예외는
Exception in thread "main" sun.print.PrintJobFlavorException: invalid flavor
at sun.print.Win32PrintJob.print(Win32PrintJob.java:327)
at Collections.PrinterJobUtil.main(PrinterJobUtil.java:89)
왜 그 텍스트 문자열이 유효한 pdf 문서라고 생각합니까? (힌트, 그렇지 않다). – jtahlborn
파일을 PDF로 부를 수는 없으며 실제 PDF 형식의 파일이어야합니다. 이것이 그 문제인지 아닌지는 모르지만 확실히 도움이되지는 않습니다. –