Home
Analytics
View/archieve combined reports
skv
Hi,
I have bunch of intermediate birt reports (documents). I want to render them in to a single doc/ppt/html/pdf document for archive and email.
Does Birt provide any way to render multiple reports in to one single document (html/pdf/ppt/doc)?
Is frame? servlet capable of rendering multiple design doc at a time?
I am having tough time combining PPT and doc reports, specially.
./SKV
Find more posts tagged with
Comments
JasonW
Currently BIRT does not handle this. You could do it with html or pdf pretty easily if you are using the RE API though. Attached is an example that uses the iText library that is already included in BIRT to combine two pdfs reports.
package REAPI;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfCopyFields;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
public class CombineReportsPDF {
public void concat(byte[] ba1, byte[] ba2, String outpath){
try{
//Document document = new Document();
//ByteArrayOutputStream baos = new ByteArrayOutputStream();
//PdfWriter writer = PdfWriter.getInstance(document, baos);
//PdfAction pdfAction = new PdfAction(PdfAction.PRINTDIALOG);
//writer.setOpenAction(pdfAction);
//document.open();
//writer.addJavaScript(
// "this.print({bUI: true,bSilent: false,bShrinkToFit: true});" +
//"\r\n" +
//"this.closeDoc();"
//);
//document.add(new Paragraph("What is this doing"));
//PdfReader js1 = new PdfReader(baos.toByteArray());
PdfReader rd1 = new PdfReader( ba1 );
PdfReader rd2 = new PdfReader( ba2 );
PdfCopyFields cpy = new PdfCopyFields( new FileOutputStream( outpath ));
//cpy.addDocument(js1);
cpy.addDocument(rd1);
cpy.addDocument(rd2);
//cpy.addJavaScript( "this.print({bUI: true,bSilent: false,bShrinkToFit: true});" +
// "\r\n" +
// "this.closeDoc();"
// );
//document.close();
cpy.close();
}catch(Exception e){
e.printStackTrace();
}
}
public void runReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");
config.setLogConfig(null, Level.OFF);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}
IReportRunnable design, design2 = null;
//Open the report design
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
design2 = engine.openReportDesign("Reports/TopSellingProducts.rptdesign");
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("Top Percentage", (new Integer(3)));
task.setParameterValue("Top Count", (new Integer(5)));
task.validateParameters();
PDFRenderOption options = new PDFRenderOption();
ByteArrayOutputStream fso= new ByteArrayOutputStream();
ByteArrayOutputStream fso2= new ByteArrayOutputStream();
options.setOutputStream(fso);
options.setOutputFormat("pdf");
task.setRenderOption(options);
task.run();
task.close();
//Create task to run and render the report,
task = engine.createRunAndRenderTask(design2);
options.setOutputStream(fso2);
options.setOutputFormat("pdf");
task.setRenderOption(options);
task.run();
task.close();
concat( fso.toByteArray(), fso2.toByteArray(), "output/resample/Combined.pdf");
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
CombineReportsPDF ex = new CombineReportsPDF( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Jason
skv
Thanks Jason.<br />
<br />
Pdf and HTML are fine, I can merge them with some third party tools but doc and PPT are really a pain. There is no production grade software to merge them. <br />
<br />
I feel BIRT should provide a way to consolidate multiple reports in to various rendering formats. <br />
<br />
./SKV<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'JasonW'" data-cid="76772" data-time="1304958217" data-date="09 May 2011 - 09:23 AM"><p>
Currently BIRT does not handle this. You could do it with html or pdf pretty easily if you are using the RE API though. Attached is an example that uses the iText library that is already included in BIRT to combine two pdfs reports.<br />
<br />
package REAPI;<br />
<br />
<br />
<br />
import java.util.logging.Level;<br />
<br />
import org.eclipse.birt.core.framework.Platform;<br />
import org.eclipse.birt.report.engine.api.EngineConfig;<br />
import org.eclipse.birt.report.engine.api.EngineException;<br />
import org.eclipse.birt.report.engine.api.PDFRenderOption;<br />
<br />
import org.eclipse.birt.report.engine.api.IReportEngine;<br />
import org.eclipse.birt.report.engine.api.IReportEngineFactory;<br />
import org.eclipse.birt.report.engine.api.IReportRunnable;<br />
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;<br />
<br />
import java.io.FileNotFoundException;<br />
import java.io.FileOutputStream;<br />
import java.io.ByteArrayOutputStream;<br />
import java.io.IOException;<br />
import java.io.OutputStream;<br />
<br />
<br />
<br />
import com.lowagie.text.pdf.PdfAction;<br />
import com.lowagie.text.pdf.PdfReader;<br />
import com.lowagie.text.pdf.PdfWriter;<br />
import com.lowagie.text.pdf.PdfCopyFields;<br />
import com.lowagie.text.Document;<br />
import com.lowagie.text.Paragraph;<br />
<br />
<br />
<br />
<br />
public class CombineReportsPDF {<br />
<br />
public void concat(byte[] ba1, byte[] ba2, String outpath){<br />
<br />
try{<br />
<br />
//Document document = new Document();<br />
//ByteArrayOutputStream baos = new ByteArrayOutputStream();<br />
//PdfWriter writer = PdfWriter.getInstance(document, baos); <br />
<br />
//PdfAction pdfAction = new PdfAction(PdfAction.PRINTDIALOG); <br />
//writer.setOpenAction(pdfAction);<br />
//document.open();<br />
//writer.addJavaScript(<br />
// "this.print({bUI: true,bSilent: false,bShrinkToFit: true});" +<br />
//"\r\n" +<br />
//"this.closeDoc();"<br />
//);<br />
//document.add(new Paragraph("What is this doing"));<br />
<br />
<br />
//PdfReader js1 = new PdfReader(baos.toByteArray());<br />
PdfReader rd1 = new PdfReader( ba1 );<br />
PdfReader rd2 = new PdfReader( ba2 );<br />
PdfCopyFields cpy = new PdfCopyFields( new FileOutputStream( outpath ));<br />
//cpy.addDocument(js1); <br />
cpy.addDocument(rd1);<br />
cpy.addDocument(rd2);<br />
//cpy.addJavaScript( "this.print({bUI: true,bSilent: false,bShrinkToFit: true});" +<br />
// "\r\n" +<br />
// "this.closeDoc();"<br />
// );<br />
//document.close();<br />
cpy.close();<br />
<br />
}catch(Exception e){<br />
e.printStackTrace();<br />
}<br />
<br />
}<br />
<br />
public void runReport() throws EngineException<br />
{<br />
<br />
IReportEngine engine=null;<br />
EngineConfig config = null;<br />
<br />
try{<br />
<br />
config = new EngineConfig( ); <br />
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");<br />
config.setLogConfig(null, Level.OFF);<br />
Platform.startup( config );<br />
IReportEngineFactory factory = (IReportEngineFactory) Platform<br />
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );<br />
engine = factory.createReportEngine( config );<br />
}catch( Exception ex){<br />
ex.printStackTrace();<br />
}<br />
<br />
IReportRunnable design, design2 = null;<br />
//Open the report design<br />
design = engine.openReportDesign("Reports/TopNPercent.rptdesign"); <br />
design2 = engine.openReportDesign("Reports/TopSellingProducts.rptdesign"); <br />
<br />
<br />
<br />
//Create task to run and render the report,<br />
IRunAndRenderTask task = engine.createRunAndRenderTask(design); <br />
task.setParameterValue("Top Percentage", (new Integer(3)));<br />
task.setParameterValue("Top Count", (new Integer(5)));<br />
task.validateParameters();<br />
<br />
PDFRenderOption options = new PDFRenderOption();<br />
ByteArrayOutputStream fso= new ByteArrayOutputStream();<br />
<br />
ByteArrayOutputStream fso2= new ByteArrayOutputStream();<br />
options.setOutputStream(fso);<br />
options.setOutputFormat("pdf");<br />
<br />
task.setRenderOption(options);<br />
task.run();<br />
task.close();<br />
<br />
//Create task to run and render the report,<br />
task = engine.createRunAndRenderTask(design2); <br />
<br />
<br />
options.setOutputStream(fso2); <br />
options.setOutputFormat("pdf");<br />
<br />
task.setRenderOption(options); <br />
<br />
<br />
task.run();<br />
task.close();<br />
<br />
concat( fso.toByteArray(), fso2.toByteArray(), "output/resample/Combined.pdf");<br />
<br />
engine.destroy();<br />
Platform.shutdown();<br />
System.out.println("Finished");<br />
} <br />
<br />
<br />
/**<br />
*
@param
args<br />
*/<br />
public static void main(String[] args) {<br />
try<br />
{<br />
<br />
CombineReportsPDF ex = new CombineReportsPDF( );<br />
ex.runReport();<br />
<br />
}<br />
catch ( Exception e )<br />
{<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
<br />
<br />
}<br />
<br />
<br />
Jason<br /></p></blockquote>
JasonW
Please log an enhancement for this.
Jason
skv
<blockquote class='ipsBlockquote' data-author="'JasonW'" data-cid="76887" data-time="1305131362" data-date="11 May 2011 - 09:29 AM"><p>
Please log an enhancement for this.<br />
<br />
Jason<br /></p></blockquote>
<br />
Sure, I will do that.<br />
<br />
Thanks, <br />
./SKV
skv
<blockquote class='ipsBlockquote' data-author="'JasonW'" data-cid="76887" data-time="1305131362" data-date="11 May 2011 - 09:29 AM"><p>
Please log an enhancement for this.<br />
<br />
Jason<br /></p></blockquote>
<br />
Hi Jason,<br />
<br />
One quick question, how do yo combine HTML reports?<br />
<br />
I am simply combining ByteArrayOutputStreams received for each of rendered reports. However, when the number of reports is large, say 10, some of combined reports are getting screwed-up formatting. <br />
<br />
Any neat way to combine HTML reports?<br />
<br />
<br />
Thanks in advance, <br />
./SKV
JasonW
When you are setting the html options make sure to select embeddable and inline styles like:
options.setOutputStream(fso);
options.setEmbeddable(true);
options.setOutputFormat("html");
options.setImageDirectory("images");
options.setEnableInlineStyle(true);
My example is as follows:
package REAPI;
import java.util.HashMap;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.RenderOption;
import java.io.FileOutputStream;
import java.io.File;
public class CombineReports {
public void runReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");
config.setLogConfig(null, Level.OFF);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}
IReportRunnable design, design2 = null;
//Open the report design
design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
design2 = engine.openReportDesign("Reports/TopSellingProducts.rptdesign");
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("Top Percentage", (new Integer(3)));
task.setParameterValue("Top Count", (new Integer(5)));
task.validateParameters();
HTMLRenderOption options = new HTMLRenderOption();
FileOutputStream fso=null, fso2=null;
try{
fso = new FileOutputStream(new File("output/resample/Combined.html"), true);
}catch (Exception e){
e.printStackTrace();
}
options.setOutputStream(fso);
options.setEmbeddable(true);
options.setOutputFormat("html");
options.setImageDirectory("images");
options.setEnableInlineStyle(true);
//ImageHandlerTest
//options.setImageHandler(new MyImageHandler());
//options.setImageHandler(new HTMLServerImageHandler());
options.setImageHandler(new HTMLCompleteImageHandler());
task.setRenderOption(options);
task.run();
//Create task to run and render the report,
task = engine.createRunAndRenderTask(design2);
try{
fso.flush();
fso.close();
fso2 = new FileOutputStream(new File("output/resample/Combined.html"), true);
}catch (Exception e){
e.printStackTrace();
}
options.setOutputStream(fso2);
task.setRenderOption(options);
task.run();
task.close();
try{
fso2.flush();
fso2.close();
}catch(Exception e){
e.printStackTrace();
}
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
CombineReports ex = new CombineReports( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Jason
skv
Jason, <br />
<br />
Seems like this method is mission in BIRT 2.3.2 engine API (engineapi.jar). I am getting compilation error.<br />
<br />
Is this a new option?<br />
<br />
<br />
[iajc] [Xlint:invalidAbsoluteTypeName]<br />
[iajc] C:\..\.. ReportRenderer.java:114 [error] The method setEnableInlineStyle(<br />
oolean) is undefined for the type HTMLRenderOption<br />
[iajc] options.setEnableInlineStyle(true);<br />
[iajc] ^^<br />
[iajc]<br />
[iajc] 1 error, 1 warning<br />
<br />
BUILD FAILED<br />
build.xml:772: compile errors: 1<br />
<br />
<br />
./SKV<br />
<br />
<blockquote class='ipsBlockquote' data-author="'JasonW'" data-cid="77227" data-time="1305823041" data-date="19 May 2011 - 09:37 AM"><p>
When you are setting the html options make sure to select embeddable and inline styles like:<br />
options.setOutputStream(fso);<br />
options.setEmbeddable(true);<br />
options.setOutputFormat("html");<br />
options.setImageDirectory("images");<br />
options.setEnableInlineStyle(true);<br />
<br />
My example is as follows:<br />
<br />
package REAPI;<br />
<br />
<br />
<br />
import java.util.HashMap;<br />
import java.util.logging.Level;<br />
<br />
import org.eclipse.birt.core.framework.Platform;<br />
import org.eclipse.birt.report.engine.api.EngineConfig;<br />
import org.eclipse.birt.report.engine.api.EngineConstants;<br />
import org.eclipse.birt.report.engine.api.EngineException;<br />
import org.eclipse.birt.report.engine.api.HTMLActionHandler;<br />
import org.eclipse.birt.report.engine.api.HTMLRenderOption;<br />
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;<br />
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;<br />
<br />
import org.eclipse.birt.report.engine.api.IReportEngine;<br />
import org.eclipse.birt.report.engine.api.IReportEngineFactory;<br />
import org.eclipse.birt.report.engine.api.IReportRunnable;<br />
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;<br />
import org.eclipse.birt.report.engine.api.RenderOption;<br />
import java.io.FileOutputStream;<br />
import java.io.File;<br />
<br />
<br />
<br />
public class CombineReports {<br />
<br />
public void runReport() throws EngineException<br />
{<br />
<br />
IReportEngine engine=null;<br />
EngineConfig config = null;<br />
<br />
try{<br />
<br />
config = new EngineConfig( ); <br />
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");<br />
config.setLogConfig(null, Level.OFF);<br />
Platform.startup( config );<br />
IReportEngineFactory factory = (IReportEngineFactory) Platform<br />
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );<br />
engine = factory.createReportEngine( config );<br />
}catch( Exception ex){<br />
ex.printStackTrace();<br />
}<br />
<br />
IReportRunnable design, design2 = null;<br />
//Open the report design<br />
design = engine.openReportDesign("Reports/TopNPercent.rptdesign"); <br />
design2 = engine.openReportDesign("Reports/TopSellingProducts.rptdesign"); <br />
<br />
<br />
<br />
//Create task to run and render the report,<br />
IRunAndRenderTask task = engine.createRunAndRenderTask(design); <br />
task.setParameterValue("Top Percentage", (new Integer(3)));<br />
task.setParameterValue("Top Count", (new Integer(5)));<br />
task.validateParameters();<br />
<br />
HTMLRenderOption options = new HTMLRenderOption();<br />
FileOutputStream fso=null, fso2=null;<br />
try{<br />
fso = new FileOutputStream(new File("output/resample/Combined.html"), true);<br />
}catch (Exception e){<br />
e.printStackTrace();<br />
}<br />
options.setOutputStream(fso);<br />
options.setEmbeddable(true);<br />
options.setOutputFormat("html");<br />
options.setImageDirectory("images");<br />
options.setEnableInlineStyle(true);<br />
<br />
//ImageHandlerTest<br />
//options.setImageHandler(new MyImageHandler());<br />
//options.setImageHandler(new HTMLServerImageHandler());<br />
options.setImageHandler(new HTMLCompleteImageHandler());<br />
task.setRenderOption(options);<br />
task.run();<br />
<br />
<br />
//Create task to run and render the report,<br />
task = engine.createRunAndRenderTask(design2); <br />
<br />
<br />
try{<br />
fso.flush();<br />
fso.close();<br />
fso2 = new FileOutputStream(new File("output/resample/Combined.html"), true);<br />
}catch (Exception e){<br />
e.printStackTrace();<br />
}<br />
options.setOutputStream(fso2); <br />
task.setRenderOption(options); <br />
<br />
<br />
task.run();<br />
task.close();<br />
try{<br />
fso2.flush();<br />
fso2.close();<br />
}catch(Exception e){<br />
e.printStackTrace();<br />
}<br />
engine.destroy();<br />
Platform.shutdown();<br />
System.out.println("Finished");<br />
} <br />
<br />
<br />
/**<br />
*
@param
args<br />
*/<br />
public static void main(String[] args) {<br />
try<br />
{<br />
<br />
CombineReports ex = new CombineReports( );<br />
ex.runReport();<br />
<br />
}<br />
catch ( Exception e )<br />
{<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
<br />
}<br />
<br />
<br />
Jason<br /></p></blockquote>
JasonW
Yes that was not available in 2.3.2.
Jason