PDF Contains Report But No Data: Please Help [message #170659] |
Thu, 15 June 2006 10:05  |
Eclipse User |
|
|
|
Folks,
I have a strange circumstance. My PDF report gets generated but
there is no data displayed--just the layout and headings of the report.
Any ideas? I have includeed my entire execution code below.
thank you in advance,
Ty
private void getPDFReport(IMarkupWriter pWriter, Object[] pParameters,
HttpServletRequest
pRequest )
{
ReportEngine engine = ReportingUtil.getEngine();
// Run reports, etc.
try
{
IReportRunnable design = getSpec( engine, (String)pParameters[ 0 ] );
// Create task to run the report and render the report
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
// Set Render context to handle url and image locataions
PDFRenderContext renderContext = new PDFRenderContext();
// renderContext.setImageDirectory("image");
HashMap<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT ,
renderContext);
task.setAppContext(contextMap);
HashMap<String, Object> parameters = new HashMap<String, Object>();
setOutgoingParameters( parameters, pParameters );
populateDatabaseConnectionParameters( design );
task.setParameterValues(parameters);
// create output stream
// ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
// Set rendering options - such as file or stream output,
// output format, whether it is embeddable, etc
RenderOptionBase optionsBase =new RenderOptionBase();
optionsBase.setOutputFormat("pdf");
String pdfReportTitle = (String) pParameters[ 0 ];
String currentDate = DateUtil.dateForFileName( ... );
String reportTitle = pdfReportTitle ... ;
StringBuffer pdfHome = new StringBuffer();
pdfHome.append( System.getProperty( "jboss.server.base.dir" ) );
pdfHome.append( File.separatorChar );
pdfHome.append( System.getProperty( "jboss.server.name" ) );
pdfHome.append( File.separatorChar );
pdfHome.append( "deploy/meco.war/DocDownload" );
String pdfFileName = reportTitle + ".pdf";
String repositoryPath = prepDocumentRepository( pRequest,
pdfHome.toString(), pdfFileName );
optionsBase.setOutputFileName( repositoryPath + "/" + pdfFileName );
task.setRenderOption( optionsBase );
task.run(); //"1-2");
task.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
// Shut down the engine.
if (engine != null)
{
engine.destroy();
}
}
private IReportRunnable getSpec( ReportEngine pEngine, String pFileName )
throws Exception
{
InputStream stream =
PDFReportRenderer.class.getClassLoader().getResourceAsStream ( pFileName );
IReportRunnable design = pEngine.openReportDesign( stream );
return design;
}
|
|
|
SOLVED: PDF Contains Report But No Data: Please Help [message #170824 is a reply to message #170659] |
Thu, 15 June 2006 18:34  |
Eclipse User |
|
|
|
Folks,
I was able to solve this with a tiny tweak. The code you see below is
a complete method that generates the PDF version of the report.
Thank you,
Ty
private void getPDFReport( Object[] pParameters, HttpServletRequest
pRequest )
{
ReportEngine engine = ReportingUtil.getEngine();
// Run reports, etc.
try
{
IReportRunnable design = getReportSpecification( engine, (String)
pParameters[ 0 ]
);
// Create task to run the report and render the report
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
// Set Render context to handle url and image locataions
PDFRenderContext renderContext = new PDFRenderContext();
// renderContext.setImageDirectory("image");
HashMap<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT ,
renderContext);
task.setAppContext(contextMap);
HashMap<String, Object> parameters = new HashMap<String, Object>();
setOutgoingParameters( parameters, pParameters );
task.setParameterValues(parameters);
populateDatabaseConnectionParameters( design );
// create output stream
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
// Set rendering options - such as file or stream output,
// output format, whether it is embeddable, etc
RenderOptionBase options = new RenderOptionBase();
options.setOutputStream( out );
options.setOutputFormat("pdf");
task.setRenderOption( options );
setPDFOutputPath(pParameters, pRequest, options);
task.run(); //"1-2");
task.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
// Shut down the engine.
if (engine != null)
{
engine.destroy();
}
}
private void setPDFOutputPath(Object[] pParameters, HttpServletRequest
pRequest, RenderOptionBase options) throws Exception
{
String pdfReportTitle = (String) pParameters[ 0 ];
String currentDate = dateForFileName( System.currentTimeMillis() );
String reportTitle = pdfReportTitle.substring( 0,
pdfReportTitle.indexOf( "." ) ) + "_" + currentDate;
StringBuffer pdfHome = new StringBuffer();
pdfHome.append( System.getProperty( "jboss.server.base.dir" ) );
pdfHome.append( File.separatorChar );
pdfHome.append( System.getProperty( "jboss.server.name" ) );
pdfHome.append( File.separatorChar );
pdfHome.append( "deploy/meco.ear/meco.war/DocDownload" );
String pdfFileName = reportTitle + ".pdf";
String repositoryPath = prepDocumentRepository( pRequest,
pdfHome.toString(), pdfFileName );
options.setOutputFileName( repositoryPath + "/" + pdfFileName );
}
private IReportRunnable getReportSpecification( ReportEngine pEngine,
String pFileName ) throws Exception
{
InputStream stream =
PDFReportRenderer.class.getClassLoader().getResourceAsStream ( pFileName );
IReportRunnable design = pEngine.openReportDesign( stream );
return design;
}
|
|
|
Powered by
FUDForum. Page generated in 0.03214 seconds