Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here i am using jasper report and .jxml file using from local drive
(like C:/jrxml/idcard.jrxml),now i want it to put with project and that should download when it generate.
anyone please suggest me what to do?
Java
public void generateReport() {

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bsaigsamed?user=root&password=root");

            InputStream input = new FileInputStream(new File("C:/jrxml/idcard.jrxml"));
            JasperDesign jasperDesign = JRXmlLoader.load(input);

            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);


            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);

            //Exporting the report
            OutputStream output = new FileOutputStream(new File("D:/Report/Reperesentative_id.pdf"));
            JasperExportManager.exportReportToPdfStream(jasperPrint, output);


            System.out.println("Report Generation Complete");
            conn.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (JRException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
Posted
Updated 9-Jul-12 19:17pm
v2

1 solution

throw it against the OS and let the OS decide on how to open it. That's easy, maintenance free and the common way.

Java
final Program p = Program.findProgram("pdf");
p.execute(printFilePath);


The user can then decide if he wants to work with it (e.g. print it) or save it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900