Jump to content

how to create a .PDF file from .xml


2005 IR Help

Recommended Posts

By: Siva - cvaram

how to create a .PDF file from .xml

2004-06-11 05:38

hi ALL,

I am very new to jasperreports.

i am trying to create .pdf file from console using the .xml

 

file created by JASPER REPORTS.

 

this is my code:

package reports;

import java.util.HashMap;

import java.util.Map;

 

import dori.jasper.engine.JRException;

 

import dori.jasper.engine.JasperCompileManager;

import dori.jasper.engine.JasperExportManager;

import dori.jasper.engine.JasperFillManager;

import dori.jasper.engine.JasperPrintManager;

import dori.jasper.engine.JasperRunManager;

 

public class Dept

{

 

private static final String TASK_COMPILE = "compile";

private static final String TASK_FILL_1 = "fill1";

private static final String TASK_FILL_2 = "fill2";

private static final String TASK_FILL_3 = "fill3";

private static final String TASK_PRINT = "print";

private static final String TASK_PDF = "pdf";

private static final String TASK_XML = "xml";

private static final String TASK_XML_EMBED = "xmlEmbed";

private static final String TASK_HTML = "html";

private static final String TASK_XLS = "xls";

private static final String TASK_CSV = "csv";

private static final String TASK_RUN = "run";

 

 

public static void main(String[] args)

{

String fileName = null;

String taskName = null;

 

if(args.length == 0)

{

usage();

return;

}

 

int k = 0;

while ( args.length > k )

{

if ( args[k].startsWith("-T") )

taskName = args[k].substring(2);

if ( args[k].startsWith("-F") )

fileName = args[k].substring(2);

 

k++;

}

 

try

{

long start = System.currentTimeMillis();

if (TASK_COMPILE.equals(taskName))

{

JasperCompileManager.compileReportToFile(fileName);

System.err.println("Compile time : " + (System.currentTimeMillis() - start));

System.exit(0);

}

else if (TASK_FILL_1.equals("fill1"))

{

//Preparing parameters

Map parameters = new HashMap();

parameters.put("ReportTitle", "Classic Report");

parameters.put("DataFile", "DeptDataSource.java");

 

JasperFillManager.fillReportToFile(fileName, parameters, new DeptDataSource());

System.err.println("Filling time : " + (System.currentTimeMillis() - start));

System.exit(0);

 

}

else if (TASK_PRINT.equals(taskName))

{

JasperPrintManager.printReport(fileName, true);

System.err.println("Printing time : " + (System.currentTimeMillis() - start));

System.exit(0);

}

else if (TASK_PDF.equals(taskName))

{

JasperExportManager.exportReportToPdfFile(fileName);

System.err.println("PDF creation time : " + (System.currentTimeMillis() - start));

System.exit(0);

}

 

 

else if (TASK_RUN.equals(taskName))

{

//Preparing parameters

Map parameters = new HashMap();

parameters.put("ReportTitle", "Classic Report");

 

JasperRunManager.runReportToPdfFile(fileName, parameters, new DeptDataSource());

System.err.println("PDF running time : " + (System.currentTimeMillis() - start));

System.exit(0);

}

else

{

usage();

System.exit(0);

}

}

catch (JRException e)

{

e.printStackTrace();

System.exit(1);

}

catch (Exception e)

{

e.printStackTrace();

System.exit(1);

}

}

 

private static void usage()

{

System.out.println( "Dept usage:" );

System.out.println( "tjava Dept -Ttask -Ffile" );

System.out.println( "tTasks : compile | fill1 | print | pdf | xml | xmlEmbed | html | xls | csv | run" );

}

 

 

}

 

 

 

 

When u say run we encountered a prob that

java.io.FileNotFoundException: Report1.xml (The system cannot find the file specified)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(Unknown Source)

at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:338)

at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:323)

at dori.jasper.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:102)

at reports.Report1.main(Report1.java:59)

 

NESTED BY :

java.io.FileNotFoundException: Report1.xml (The system cannot find the file specified)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(Unknown Source)

at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:338)

at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:323)

at dori.jasper.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:102)

at reports.Report1.main(Report1.java:59)

 

NESTED BY :

dori.jasper.engine.JRException: Report1.xml (The system cannot find the file specified)

at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:343)

at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:323)

at dori.jasper.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:102)

at reports.Report1.main(Report1.java:59)

Caused by: java.io.FileNotFoundException: Report1.xml (The system cannot find the file specified)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(Unknown Source)

at dori.jasper.engine.xml.JRXmlLoader.load(JRXmlLoader.java:338)

... 3 more

 

Solution pls

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...