Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Double sided printing of multiple reports?(Problems with double sided printing of multiple reports?)
Double sided printing of multiple reports? [message #661364] Thu, 24 March 2011 11:47 Go to next message
aca Missing name is currently offline aca Missing nameFriend
Messages: 35
Registered: March 2011
Member
Hi,
I wonder if there's is a way to guarantee a correct double sided printing of multiple reports?
I use BIRT 2.6.2 to generate several reports, which I concatinate into one big pdf printout. When printing the pdf I would like to have double sided printouts, BUT keep the different reports separate, so that each report starts on an new paper instead of the backside of the previous.
I was thinking about checking the pagenumber on each report and insert a blank page if a report ends on an uneven number.
Anyone know if this works? Or is there another way to do this?

Tnx in advance!
Re: Double sided printing of multiple reports? [message #661475 is a reply to message #661364] Thu, 24 March 2011 18:57 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

If you are using the run task you can always check the number of pages
using the rptdocument.

IReportDocument document = null;
//Open the report document
document = engine.openReportDocument("output/resample/mcb.rptdocument");
long pgcnt = document.getPageCount();

Jason

On 3/24/2011 7:47 AM, aca wrote:
> Hi,
> I wonder if there's is a way to guarantee a correct double sided
> printing of multiple reports?
> I use BIRT 2.6.2 to generate several reports, which I concatinate into
> one big pdf printout. When printing the pdf I would like to have double
> sided printouts, BUT keep the different reports separate, so that each
> report starts on an new paper instead of the backside of the previous. I
> was thinking about checking the pagenumber on each report and insert a
> blank page if a report ends on an uneven number. Anyone know if this
> works? Or is there another way to do this?
>
> Tnx in advance!
Re: Double sided printing of multiple reports? [message #661562 is a reply to message #661475] Fri, 25 March 2011 11:03 Go to previous messageGo to next message
aca Missing name is currently offline aca Missing nameFriend
Messages: 35
Registered: March 2011
Member
Thanks for the quick reply. I'm a newbie to BIRT and especially version 2.6.2 but I will try your tip as soon as I get there... Smile

[Updated on: Fri, 25 March 2011 11:04]

Report message to a moderator

Re: Double sided printing of multiple reports? [message #667888 is a reply to message #661475] Mon, 02 May 2011 15:39 Go to previous messageGo to next message
aca Missing name is currently offline aca Missing nameFriend
Messages: 35
Registered: March 2011
Member
Hi again! I'm back on track for this double siden printing problem.
I have found the task.run(), but task = engine.createRunAndRenderTask, which according to te engine API is a separate task from the RunTask you mentioned.
Questions:
1. Is it possible to solve this problem with the RunAndRenderTask?
2. If not, what's the difference in the end result (= pdf document) if you use RunAndRenderTask or the combination of RunTask and RenderTask?

Regards
Aca
Re: Double sided printing of multiple reports? [message #667914 is a reply to message #667888] Mon, 02 May 2011 18:35 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

The run task creates a rptdocument that can be rendered with a render
task. It allows you to get report output meta data like table of
contents, bookmarks and number of pages. The render task can be set to
render all pages or a page at a time. This is not possible with a
runandrender task which just runs the report and renders it in one task
and does not create a rptdocument.

Jason

On 5/2/2011 11:39 AM, aca wrote:
> Hi again! I'm back on track for this double siden printing problem.
> I have found the task.run(), but task = engine.createRunAndRenderTask,
> which according to te engine API is a separate task from the RunTask you
> mentioned. Questions:
> 1. Is it possible to solve this problem with the RunAndRenderTask?
> 2. If not, what's the difference in the end result (= pdf document) if
> you use RunAndRenderTask or the combination of RunTask and RenderTask?
> Regards
> Aca
Re: Double sided printing of multiple reports? [message #668069 is a reply to message #667914] Tue, 03 May 2011 15:22 Go to previous messageGo to next message
aca Missing name is currently offline aca Missing nameFriend
Messages: 35
Registered: March 2011
Member
Thanks once again for the quick response!
I have changed to using the runTask and renderTask and now the pageCount works perfect.
One last (?) question:
I have added an empty last page by creating an empty rptdesign and adding that to the bao list. This works just fine, but do you know of another smoother way to add an empty page to the reportDocument or the rendered pdf?

Aca
Re: Double sided printing of multiple reports? [message #668097 is a reply to message #668069] Tue, 03 May 2011 17:47 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Are you calling the iText libraries directly? Maybe the
PdfCopyFields.addDocument will work. I have an RE API example that
combines to report outputs. I am attaching it.

Jason

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\\ReportEngi ne ");
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();
}
}



}





On 5/3/2011 11:22 AM, aca wrote:
> Thanks once again for the quick response!
> I have changed to using the runTask and renderTask and now the pageCount
> works perfect.
> One last (?) question:
> I have added an empty last page by creating an empty rptdesign and
> adding that to the bao list. This works just fine, but do you know of
> another smoother way to add an empty page to the reportDocument or the
> rendered pdf?
>
> Aca
Re: Double sided printing of multiple reports? [message #668627 is a reply to message #668097] Fri, 06 May 2011 13:31 Go to previous messageGo to next message
aca Missing name is currently offline aca Missing nameFriend
Messages: 35
Registered: March 2011
Member
Thanks a lot for the API, I've tried it and it works. For other reasons we did however choose to use an empty rpt-design instead, but I will save the API anyway Smile

I'm having some problem with the pageCount which in tests turned out to be not so perfect. A printout with a dynamic list that is shown on two pages still returns a pagecount of 1. Any clue why?

Here is the create-method in which I have replaced RunAndRenderTask with a RunTask and a RenderTask.

public ByteArrayOutputStream createReport(String reportDesignName, String reportDocumentName, Object reportObject, Boolean printSettingDoubleSided)
throws ReportException {
ServletContext servletContext = WebHelper.getServletContext();
ByteArrayOutputStream pdfBaos = new ByteArrayOutputStream();

IRunTask runTask = null;
IRenderTask renderTask = null;

HashMap<String, Object> appContext = new HashMap<String, Object>();
appContext.put("reportObject", reportObject);

try {
IReportEngine engine = BirtEngine.getBirtEngine();

// RUN
String designHome = servletContext.getRealPath(ReportingConstants.REPORT_DESIGN_ PATH);
log.debug("RealPath to Birt report: " + designHome);
IReportRunnable report = engine.openReportDesign(designHome + reportDesignName);

runTask = engine.createRunTask(report);
runTask.setAppContext(appContext);

String documentHome = servletContext.getRealPath(ReportingConstants.REPORT_DOCUMEN T_PATH);
runTask.run(documentHome + reportDocumentName);

// RENDER
IReportDocument reportDocument = engine.openReportDocument(documentHome + reportDocumentName);
renderTask = engine.createRenderTask(reportDocument);
renderTask.setAppContext(appContext);

HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler();

HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(IRenderOption.OUTPUT_FORMAT_PDF);
options.setOutputStream(pdfBaos);

options.setImageDirectory("./images");
options.setImageHandler(imageHandler);

renderTask.setRenderOption(options);
renderTask.render();

long pageCount = reportDocument.getPageCount();
if(printSettingDoubleSided && pageCount % 2 > 0) {
//add an empty last page and concatenate into one baos
System.out.println(reportDesignName +" har udda antal sidor");
List<ByteArrayOutputStream> pdfBaosListTemporary = new ArrayList<ByteArrayOutputStream>();
pdfBaosListTemporary.add(pdfBaos);
pdfBaosListTemporary.add(createEmptyReport());
pdfBaos = concatPdfs(pdfBaosListTemporary, false);
}

reportDocument.close();

} catch(EngineException e) {
log.error(e.toString());
throw new ReportException("[createReport] Error when creating report:" + reportDesignName);
} catch(BirtException e) {
log.error(e.toString());
throw new ReportException("[createReport] Error when trying to create reportengine in creating report:"
+ reportDesignName);
} finally {
if(runTask != null) {
runTask.close();
}
if(renderTask != null) {
renderTask.close();
}
}
//return baos;
return pdfBaos;
}
Re: Double sided printing of multiple reports? [message #668667 is a reply to message #668627] Fri, 06 May 2011 16:04 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Are you saying the reportDocument.getPageCount() method is only
returning 1? Can you reproduce with the sample db so I can run the
report here and have a look at it?

BTW if you are going to render to PDF you do not need to use
HTMLRenderOption. Use PDFRenderOption like:
PDFRenderOption options = new PDFRenderOption();
options.setOption(IPDFRenderOption.PDF_HYPHENATION, true);
options.setOption(IPDFRenderOption.PDF_TEXT_WRAPPING, true);
options.setOption(IPDFRenderOption.PAGE_OVERFLOW,
IPDFRenderOption.FIT_TO_PAGE_SIZE);
//options.setOption(IPDFRenderOption.DPI, 300);

options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");
options.setOutputFileName("output/resample/file2.pdf");
options.setOutputFormat("pdf");

Jason

On 5/6/2011 9:31 AM, aca wrote:
> Thanks a lot for the API, I've tried it and it works. For other reasons
> we did however choose to use an empty rpt-design instead, but I will
> save the API anyway :)
>
> I'm having some problem with the pageCount which in tests turned out to
> be not so perfect. A printout with a dynamic list that is shown on two
> pages still returns a pagecount of 1. Any clue why?
>
> Here is the create-method in which I have replaced RunAndRenderTask with
> a RunTask and a RenderTask.
> public ByteArrayOutputStream createReport(String reportDesignName,
> String reportDocumentName, Object reportObject, Boolean
> printSettingDoubleSided)
> throws ReportException {
> ServletContext servletContext = WebHelper.getServletContext();
> ByteArrayOutputStream pdfBaos = new ByteArrayOutputStream();
>
> IRunTask runTask = null;
> IRenderTask renderTask = null;
>
> HashMap<String, Object> appContext = new HashMap<String, Object>();
> appContext.put("reportObject", reportObject);
>
> try {
> IReportEngine engine = BirtEngine.getBirtEngine();
>
> // RUN
> String designHome =
> servletContext.getRealPath(ReportingConstants.REPORT_DESIGN_ PATH);
> log.debug("RealPath to Birt report: " + designHome);
> IReportRunnable report = engine.openReportDesign(designHome +
> reportDesignName);
>
> runTask = engine.createRunTask(report);
> runTask.setAppContext(appContext);
>
> String documentHome =
> servletContext.getRealPath(ReportingConstants.REPORT_DOCUMEN T_PATH);
> runTask.run(documentHome + reportDocumentName);
>
> // RENDER
> IReportDocument reportDocument = engine.openReportDocument(documentHome
> + reportDocumentName);
> renderTask = engine.createRenderTask(reportDocument);
> renderTask.setAppContext(appContext);
>
> HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler();
>
> HTMLRenderOption options = new HTMLRenderOption();
> options.setOutputFormat(IRenderOption.OUTPUT_FORMAT_PDF);
> options.setOutputStream(pdfBaos);
>
> options.setImageDirectory("./images");
> options.setImageHandler(imageHandler);
>
> renderTask.setRenderOption(options);
> renderTask.render();
>
> long pageCount = reportDocument.getPageCount();
> if(printSettingDoubleSided && pageCount % 2 > 0) {
> //add an empty last page and concatenate into one baos
> System.out.println(reportDesignName +" har udda antal sidor");
> List<ByteArrayOutputStream> pdfBaosListTemporary = new
> ArrayList<ByteArrayOutputStream>();
> pdfBaosListTemporary.add(pdfBaos);
> pdfBaosListTemporary.add(createEmptyReport());
> pdfBaos = concatPdfs(pdfBaosListTemporary, false);
> }
> reportDocument.close();
>
> } catch(EngineException e) {
> log.error(e.toString());
> throw new ReportException("[createReport] Error when creating report:" +
> reportDesignName);
> } catch(BirtException e) {
> log.error(e.toString());
> throw new ReportException("[createReport] Error when trying to create
> reportengine in creating report:"
> + reportDesignName);
> } finally {
> if(runTask != null) {
> runTask.close();
> }
> if(renderTask != null) {
> renderTask.close();
> }
> }
> //return baos;
> return pdfBaos;
> }
>
Re: Double sided printing of multiple reports? [message #668672 is a reply to message #668667] Fri, 06 May 2011 16:28 Go to previous messageGo to next message
aca Missing name is currently offline aca Missing nameFriend
Messages: 35
Registered: March 2011
Member
I'm not sure what you mean by "reproduce the the sample db". We use BIRT in a Java project where the data are collected from different services. when testing locally we use a simulator that renders predefined replies.
What exactly do you need? I can see if I can simplify a report and still get the pagenumber problem...
Re: Double sided printing of multiple reports? [message #668679 is a reply to message #668672] Fri, 06 May 2011 16:40 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

I need a report I can run in my debug environment to test it. That is
why I asked if you could recreate the issue with a report that uses the
classic models sample db.

Jason

On 5/6/2011 12:28 PM, aca wrote:
> I'm not sure what you mean by "reproduce the the sample db". We use BIRT
> in a Java project where the data are collected from different services.
> when testing locally we use a simulator that renders predefined replies.
> What exactly do you need? I can see if I can simplify a report and still
> get the pagenumber problem...
Re: Double sided printing of multiple reports? [message #668684 is a reply to message #668679] Fri, 06 May 2011 17:25 Go to previous messageGo to next message
aca Missing name is currently offline aca Missing nameFriend
Messages: 35
Registered: March 2011
Member
I understand. I have to get back to you on that, as I haven't ever used a database when creating reports.
It's getting late here (= Sweden) so I will have a look at it next week. How do I send the report when I've connected it to the sample db?

Have a nice weekend!
Aca

[Updated on: Fri, 06 May 2011 17:26]

Report message to a moderator

(no subject) [message #668688 is a reply to message #668684] Fri, 06 May 2011 17:53 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You can just email it to me at jasonweathersby at windstream dot net.
The classic models db is an embedded derby database and it is included
in birt so you should not have to connect to an external db.

Jason

On 5/6/2011 1:25 PM, aca wrote:
> I understand. I have to get back to you on that, as I haven't ever used
> a database when createing reports. It's getting late here (= Sweden) so
> I will have a look at it next week. How do I sent the report when I've
> connected it to the sample db?
>
> Have a nice weekend!
> Aca
Re: (no subject) [message #669524 is a reply to message #668688] Tue, 10 May 2011 15:09 Go to previous message
aca Missing name is currently offline aca Missing nameFriend
Messages: 35
Registered: March 2011
Member
After changing the Layout preference to Fixed layout, the pageCount now works as expected for the generated pdf.
Thanks again for all the support!
Aca
Previous Topic:Joining on a multivalue string
Next Topic:How to get created report document from SWT Browser?
Goto Forum:
  


Current Time: Tue Apr 16 09:49:53 GMT 2024

Powered by FUDForum. Page generated in 0.70160 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top