|
Re: Somebody uses the BIRT API to generate a REport [message #709975 is a reply to message #709651] |
Thu, 04 August 2011 14:49 |
|
If you nest the toc entries in BIRT they should show up nested. Take a
look at the attached report. Preview it in the WebViewer and click on
the TOC icon. I am also attaching a simple class that shows how to
iterate over the same reports toc using the api. I did a little work
with a first page TOC using BIRT and iText. It is not complete but I am
attaching it as well. It only generates the first level, but there is a
comment in the code where "Kids" field is used to get nested bookmarks
using iText. Have a look.
Jason
On 8/4/2011 2:18 AM, Dude wrote:
> Hello Eclipse Community
>
> I am looking for somebody who has some experience using the BIRT API and
> can help me.
>
> I want to create a printable TOC with maintopic and subtopic like this
> 1. maintopic
> 1.2 subtopic
>
> The API provides a lot of Objects to create a TOC but I just don´t get
> it how they are working together.
>
> Another possibility to get a TOC is to use bookmnarks and to add them
> children this works fine on iText but in BIRT there is no way (so far as
> I know) to add children to a bookmark.
>
> I posted this problem in other Forums too but no answer I am hopeing
> here is someone who knows about BIRT.
>
> Is there any tutorial of how to use the API?
>
> Thanks a lot
> Dude
-
Attachment: toccode.zip
(Size: 5.86KB, Downloaded 300 times)
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #710550 is a reply to message #709975] |
Fri, 05 August 2011 06:20 |
Dude Messages: 20 Registered: August 2011 |
Junior Member |
|
|
Thanks for your reply and your attached code
I will try it
One thing i allready figured it out is that the way you set your BIRT Home parameter does not work for me i have to do it this way:
config.setProperty( "BIRT_HOME", "C:/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine" );
I am missing some jar files at my buildpath may you can post yours thanks a lot
Dude
[Updated on: Fri, 05 August 2011 06:55] Report message to a moderator
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #710643 is a reply to message #710550] |
Fri, 05 August 2011 08:53 |
Dude Messages: 20 Registered: August 2011 |
Junior Member |
|
|
I fixed the buildpath issue the wrong Version of Birt was in it.
But now I am facing another problem
I get a NullPointer Exception at this Point
engine = factory.createReportEngine( config );
Stacktrace:
java.lang.NullPointerException
at org.eclipse.birt.report.engine.api.impl.ReportEngine$EngineExtensionManager.<init>(ReportEngine.java:804)
at org.eclipse.birt.report.engine.api.impl.ReportEngine.<init>(ReportEngine.java:110)
at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory$1.run(ReportEngineFactory.java:18)
at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory$1.run(ReportEngineFactory.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.birt.report.engine.api.impl.ReportEngineFactory.createReportEngine(ReportEngineFactory.java:14)
at birt.test.GenerateFirstPageTocPDF.runReport(GenerateFirstPageTocPDF.java:132)
at birt.test.GenerateFirstPageTocPDF.main(GenerateFirstPageTocPDF.java:187)
engine is null which means that the method createReportEngine returns null.
but config coudn´t be null because I use it to start the Platform and this works.
I downloaded the BIRT ReportEngine 2.6.1
Do I need a other library
Any idea what´s wrong? I use exactly your code
Thanks
Dude
[Updated on: Fri, 05 August 2011 11:28] Report message to a moderator
|
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #713589 is a reply to message #713175] |
Mon, 08 August 2011 16:05 |
|
We have an enhancement filed to add a toc report element, but I am not
sure when it will get implemented. The code should have produced a pdf
with a toc at the beginning. Did it not?
Jason
On 8/8/2011 3:24 AM, Dude wrote:
> I fixed this problem too but the result is not excatly what I expect.
> I would like to have a prinbtable TOC at the begining of my report just
> like the toc create in bookmarks.
>
> Is that possible in BIRT ?
>
> Thanks Dude
|
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #714101 is a reply to message #713806] |
Tue, 09 August 2011 19:27 |
|
I modified the example a bit further to add sub categories (only does 2
levels currently) and add the page numbers. Attached is the source and
the report and an example of the output.
Jason
On 8/9/2011 1:51 AM, Dude wrote:
> I would not call it a TOC it´s more a list of the maintopic numbers.
> Not like the TOC you can see at the left side with bookmarks this is
> what I want.
> I would like to have a printable TOC which means TOC you know from books
> 1.main
> 1.1 sub
> 1.1.1 sub sub
> 1.2 sub
> 2. main
>
> And so on....
>
> I allready got a part solution with bookmarks and iText.
> With this you add bookmarks to your report and cycle over it using iText.
> And the subtopic will be created in spite of the bookmark kids that works
> But I couldn´t get it done to add kids elements to my bookmarks using
> the BIRT API
>
> Dude
|
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #714463 is a reply to message #714367] |
Wed, 10 August 2011 14:56 |
|
We have a bugzilla entry for adding a printable toc component. It is
just not implemented yet. We already use iText to generate the PDFs so
that is why I just went ahead an built it that way.
The error you are getting is because you have an older version of BIRT
than I am using. What version are you currently using?
Jason
On 8/10/2011 8:37 AM, Dude wrote:
> Thanks for the code this TOC is what i am looking for.
> But I have some genral questions ande about your code.
> First you use iText to produce the TOC.
> In the BIRT API there are a lot of "TOC Objects" have you ever tried to
> get it done with them?
> I am just wondering how the objects are working together and why there
> is no possibility to create a printable TOC in BIRT.
> And if I try to open your TOC.rptdesign i get the following error
> messeage from my eclipse "The report file version '3.2.22' is not
> supported"
> Do you have any suggestions?
>
> Thanks a lot Dude
|
|
|
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #715178 is a reply to message #715116] |
Fri, 12 August 2011 15:29 |
|
I believe this will be implemented but I am not certain when. I am
modifying the code I posted to be more generic and handle more than two
levels. Maybe we can modify pdf emitter to have this as automatic
option, when emitting. Once I finish the updated code I may write a
blog post on how it works.
Jason
On 8/12/2011 8:10 AM, Dude wrote:
> Thanks for the link Is it possible that this feature is implemented in
> the near future or rather not(never ;) )?
>
> In my opinion this is a fundamental feature for a reporting tool and the
> warkarround("hack") with iText works but isn´t the prettiest.
>
> Dude
|
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #716229 is a reply to message #716136] |
Tue, 16 August 2011 17:47 |
|
Attached is the modified class. It handles recursive toc entries now
and applies a little styling.
We are looking into adding something like this in the pdf emitter. Do
you see a need for a toc component for other output format?
Jason
On 8/16/2011 10:19 AM, Dude wrote:
> Okay thanks for the informations i hope that this feature will be
> implemented.
> Autimatic generation of a TOC as an option would be very nice i guess
> lot of people would appreciate it Can you post the link for your blog
> for the or send me your modified code?
>
> Dude
>
>
package REAPI;
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
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.IRenderTask;
import org.eclipse.birt.report.engine.api.IReportDocument;
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.IRunTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
import com.lowagie.text.Chunk;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfArray;
import com.lowagie.text.pdf.PdfDestination;
import com.lowagie.text.pdf.PdfDictionary;
import com.lowagie.text.pdf.PdfOutline;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.SimpleBookmark;
import com.lowagie.text.pdf.SimpleNamedDestination;
import com.lowagie.text.pdf.draw.DottedLineSeparator;
public class GenerateFirstPageTocPDF {
private final static int tocperpage = 40;
private int toccounter=0;
private int pagecnt=1;
private PdfStamper stamper = null;
private ColumnText column = null;
private PdfPTable table = null;
private HashMap bookmarkPages = null;
private Rectangle rect = null;
private Chunk separator = null;
private Color tocColor = new Color(245,245,245);
public void insertPages(List<HashMap<String, Object>> list){
for (HashMap<String, Object> bookmark : list) {
this.toccounter++;
if( this.toccounter > this.tocperpage){
this.pagecnt++;
this.stamper.insertPage(this.pagecnt, this.rect);
this.toccounter=0;
}
List<HashMap<String, Object>> clist = (List) bookmark.get("Kids");
if(clist != null){
insertPages(clist);
}
}
}
public void handleEntries( List<HashMap<String, Object>> list, int level){
PdfPCell cell = null;
Chunk link;
PdfAction action;
for (HashMap<String, Object> bookmark : list) {
link = new Chunk((String)bookmark.get("Title"));
action =PdfAction.gotoLocalPage((String) bookmark.get("Title"), false);
link.setAction(action);
String bookmarkString = (String) bookmarkPages.get((String) bookmark.get("Title"));
String[] pga =bookmarkString.split(" "); //pga[0] contains page number
Phrase ph = new Phrase(" ");
ph.setFont( new Font(Font.TIMES_ROMAN, 8));
ph.add(new Chunk(link));
cell = new PdfPCell(ph);
cell.setBorder(PdfPCell.NO_BORDER);
cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
cell.setBackgroundColor(this.tocColor);
cell.setIndent(level*4);
this.table.addCell(cell);
cell = new PdfPCell(ph);
cell.setBorder(PdfPCell.NO_BORDER);
cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
cell.setBackgroundColor(this.tocColor);
//cell.setBorderColor(Color.BLACK);
//cell.setBorderWidthBottom(1);
cell.addElement(this.separator);
this.table.addCell(cell);
ph = new Phrase(pga[0]);
ph.setFont( new Font(Font.TIMES_ROMAN, 8));
cell = new PdfPCell(ph);
cell.setBorder(PdfPCell.NO_BORDER);
cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
cell.setBackgroundColor(this.tocColor);
Color cc = new Color(level, level, level, level);
//cell.setBorderColor(Color.BLACK);
//cell.setBorderWidthBottom(1);
this.table.addCell(cell);
this.toccounter++;
if( this.toccounter > this.tocperpage){
this.pagecnt = this.pagecnt+1;
this.column.addElement(table);
try {
this.column.go();
} catch (DocumentException e) {
e.printStackTrace();
}
this.column = new ColumnText(this.stamper.getOverContent(this.pagecnt));
this.column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36),
this.rect.getRight(36), this.rect.getTop(36));
float[] colsWidth = {0.5f, 2f, 0.2f};
this.table = new PdfPTable(colsWidth);
this.table.setWidthPercentage(85);
this.toccounter=0;
}
List<HashMap<String, Object>> clist = (List) bookmark.get("Kids");
if( clist != null){
level++;
handleEntries( clist, level);
level--;
}
}
}
public void createTOC(ByteArrayOutputStream baos, String outpath){
try {
PdfReader reader = new PdfReader(baos.toByteArray());
PdfDictionary pdfd = reader.getCatalog();
this.rect = reader.getPageSizeWithRotation(1);
this.stamper = new PdfStamper(reader, new FileOutputStream(outpath));
stamper.setViewerPreferences(PdfWriter.PageModeUseOutlines);
stamper.insertPage(1, rect);
PdfOutline pdfo = stamper.getWriter().getRootOutline();
this.column = new ColumnText(stamper.getOverContent(1));
this.column.setSimpleColumn(this.rect.getLeft(36), this.rect.getBottom(36),
this.rect.getRight(36), this.rect.getTop(36));
this.separator = new Chunk(new DottedLineSeparator());
PdfPTable header = new PdfPTable(1);
Phrase ph = new Phrase("Table Of Contents");
ph.setFont( new Font(Font.TIMES_ROMAN, 8));
PdfPCell cell = new PdfPCell(ph);
cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
cell.setBackgroundColor(this.tocColor);
cell.setBorder(PdfPCell.NO_BORDER);
header.addCell(cell);
header.setWidthPercentage(85);
this.column.addElement(header);
List<HashMap<String, Object>> list = SimpleBookmark.getBookmark(reader);
this.toccounter=0;
this.pagecnt=1;
insertPages(list);
this.toccounter=0;
this.pagecnt=1;
//put this before insertPage to get the orignal page count
//using it here gets the updated bookmark page numbers
this.bookmarkPages = SimpleNamedDestination.getNamedDestination(reader, false);
SimpleBookmark.shiftPageNumbers(list, reader.getNumberOfPages(), null);
float[] colsWidth = {0.5f, 2f, 0.2f};
this.table = new PdfPTable(colsWidth);
this.table.setWidthPercentage(85);
if( list != null){
handleEntries( list,0);
}
this.column.addElement(table);
this.column.go();
this.stamper.close();
reader.close();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException 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/TOC.rptdesign");
//Create task to run and render the report,
IRunTask task = engine.createRunTask(design);
task.run("output/resample/toc.rptdocument");
task.close();
IReportDocument document = null;
//Open the report design
document = engine.openReportDocument("output/resample/toc.rptdocument");
IRenderTask rtask = engine.createRenderTask(document);
PDFRenderOption options = new PDFRenderOption();
ByteArrayOutputStream fso= new ByteArrayOutputStream();
options.setOutputStream(fso);
//options.setOutputFileName("c:/test5/jj.pdf");
options.setOutputFormat("pdf");
rtask.setRenderOption(options);
rtask.render();
rtask.close();
createTOC(fso, "c:/test/final.pdf");
//createToc(fso, "c:/test5/what2.pdf");
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
GenerateFirstPageTocPDF ex = new GenerateFirstPageTocPDF( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
|
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #716504 is a reply to message #716450] |
Wed, 17 August 2011 15:05 |
|
I am using the version of iText that the BIRT engine uses in the PDF
emitter. I believe it is 2.1.7. Since we use iText in the emitter we
will most likely use the iText features to generate a toc.
Jason
On 8/17/2011 8:51 AM, Dude wrote:
> One Question about your code
> Which Version of iText do you use because the package structur of your
> imports are different to mine yours: import
> com.lowagie.text.pdf.draw.DottedLineSeparator;
> mine: import com.itextpdf.text.pdf.draw.DottedLineSeparator;
>
> And some function does not work like in your code the functions are
> different for example
> private BaseColor tocColor = new BaseColor( 245, 245, 245 );
> cell.setBackgroundColor( this.tocColor );
> Here you need a BaseColor not a Color like on your code
> I use iText Version 5.1.1
>
> About your question in my opinion a TOC makes the most sense in a pdf
> format but in word it would be nice too I never converted my Report to
> Word don´t know wheter is used often or not but I guess this would make
> sense. In other output not so much.
>
> One Question about the implementation you plan Do you thinking about to
> use iText to get it done or handle it in other ways in your PdfEmitter
>
> Dude
|
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #722680 is a reply to message #722327] |
Tue, 06 September 2011 14:02 |
|
Thanks for the comments. We are looking to see if we can support this
in pdf and word output formats for the next release.
Jason
On 9/5/2011 7:42 AM, Dude wrote:
> Hey I know it´s been a while but I just come up with an suggestion or
> whish if you want to call it like this ;)
> I think it would be great if you can add a field for example "headline"
> to your report desgin and while BIRT convert it to PDF it checks the
> report for this fields and creates the TOC with the help of thm this
> would be greate. And to make it awesome this whole progress should work
> nested. Just some thoughts from me.
> Dude
>
|
|
|
Re: Somebody uses the BIRT API to generate a REport [message #722683 is a reply to message #722327] |
Tue, 06 September 2011 14:02 |
|
Thanks for the comments. We are looking to see if we can support this
in pdf and word output formats for the next release.
Jason
On 9/5/2011 7:42 AM, Dude wrote:
> Hey I know it´s been a while but I just come up with an suggestion or
> whish if you want to call it like this ;)
> I think it would be great if you can add a field for example "headline"
> to your report desgin and while BIRT convert it to PDF it checks the
> report for this fields and creates the TOC with the help of thm this
> would be greate. And to make it awesome this whole progress should work
> nested. Just some thoughts from me.
> Dude
>
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05701 seconds