Print a PDF file using PrinterJob in Java

前端 未结 5 1622
误落风尘
误落风尘 2020-12-01 08:30

I have an issue when trying to print a PDF file using Java. Here is my code:

PdfReader readFtp = new PdfReader();    // This class is used for reading a PDF          


        
5条回答
  •  情深已故
    2020-12-01 09:15

    Try this code:

    FileInputStream fis = new FileInputStream(“C:/mypdf.pdf”);
    Doc pdfDoc = new SimpleDoc(fis, null, null);
    DocPrintJob printJob = printService.createPrintJob();
    printJob.print(pdfDoc, new HashPrintRequestAttributeSet());
    fis.close();
    

    You can also follow these steps

提交回复
热议问题