Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to display file download dialog for PDF in jax-rs?
    primarykey
    data
    text
    <p>I'm creating REST app and PDF using <code>Jasper Report</code> and would like to display file download dialog for PDF on browser.</p> <p>This is exactly what I am looking for:<br /> <a href="http://www.mkyong.com/webservices/jax-rs/download-pdf-file-from-jax-rs/" rel="nofollow">http://www.mkyong.com/webservices/jax-rs/download-pdf-file-from-jax-rs/</a></p> <p>My code below creates PDF file (MyAwesomeJasperReport25.pdf) but file download dialog does not show up on the browser and I don't understand why.</p> <pre><code>@GET @Path("pdf") @Produces("application/pdf") public Response outputPDF() { OutputStream output = null; try { File jrxmlFile = new File("C:\\Users\\m-takayashiki\\report2.jrxml"); if(jrxmlFile.exists()) { //jrxml compile JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlFile.getAbsolutePath()); //some code emitted JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource); String filePath = "C:\\Users\\m-takayashiki\\MyAwesomeJasperReport25.pdf"; output = new FileOutputStream(new File(filePath)); JasperExportManager.exportReportToPdfStream(jasperPrint, output); // From here trying to ask user to download PDF ResponseBuilder response = Response.ok((Object) filePath); response.header("Content-disposition", "attachment; filename=MyAwesomeJasperReportDownload.pdf"); return response.build(); } } catch(Exception e) { System.out.println("-------------------- PDF exception "); System.out.println(e); return null; } finally { try { if(output != null) { output.close(); } } catch(Exception e) { System.out.println(e); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload