Automatically open the printer dialog after providing PDF download

前端 未结 3 1912
灰色年华
灰色年华 2020-11-28 11:38

I am currently opening a pdf file in a new tab in my browser but I need to know how to open a printer dialog to print the pdf jasper report after pressing a commandButton

3条回答
  •  独厮守ぢ
    2020-11-28 11:59

    With JasperReports

    When using JasperReports, simply add this parameter to JasperReports exporter:

    exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print();");
    

    This basically instructs Adobe Acrobat to execute the script this.print() when opening the PDF. See also page 79-80 of Adobe Acrobat Scripting Guide. Below is an extract of relevance:

    Printing PDF Documents

    It is possible to use Acrobat JavaScript to specify whether a PDF document is sent to a printer or to a PostScript file. In either case, to print a PDF document, invoke the doc object’s print method. [...]


    Without JasperReports

    If you don't have control over generation of PDFs and thus can't manipulate it to add the mentioned script, an alternative is to change all the Java/JSF code accordingly so that the PDF file is idempotently available (i.e. the PDF file must be available by just a GET request rather than a POST request). This allows you to embed it in an