Automatic print is not working in Java

后端 未结 2 1068
深忆病人
深忆病人 2021-02-19 20:40

I have a requirement to print pdf files in two different ways -one through web page where user will see the print preview and choose the printer and print it. Second way is to a

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 21:23

    Have you tried JPadel to print PDF files:

    Excerpt from Sample codes

    final PdfBook pdfBook = new PdfBook(pdfDecoder, printJob.getPrintService(), attributes);
    pdfBook.setChooseSourceByPdfPageSize(false);
    
    final SimpleDoc doc = new SimpleDoc(pdfBook, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
    
    // used to track print activity
    printJob.addPrintJobListener(new PDFPrintJobListener());
    
    try {
        printJob.print(doc, attributes);
    }
    catch (final Exception e) {
        LogWriter.writeLog("Exception " + e + " printing");
        // 
    }
    

    In addition to this you can provide the printer name and add a listner PDFPrintJobListener as well.

提交回复
热议问题