Jasper report esportare un report in pdf [by sc]

308 views

Published on

Jasper report esportare un report in pdf [by sc]

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
308
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Jasper report esportare un report in pdf [by sc]

  1. 1. Come Esportare un report in PDF Le seguenti righe di codice mostrano come esportare un report in formato pdf. Nell’esempio di utilizza una connessione con MySql (ma quanto detto vale per qualunque db). Nel codice si considera un report di nome report1.jasper posto nella cartella c:/reports. Il pdf creato avrà il nome report1.pdf // Carica il driver Class.forName("com.mysql.jdbc.Driver").newInstance(); // Connessione a Mysql Connection cnn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname","root","password"); HashMap hm=new HashMap(); // Riempie il report template (file jasper) con i dati JasperPrint print=JasperFillManager.fillReport("C:/reports/report1.jasper", hm, cnn); // Esporta in pdf JRExporter exporter=new JRPdfExporter(); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:/reports/report1.pdf"); exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.exportReport(); // Chiude la connessione cnn.close();

×