Page number and total page [message #774451] |
Tue, 03 January 2012 18:52  |
Eclipse User |
|
|
|
I have a requirement to add page number and total page to the report directly, which is a form. I copy and paste those 2 fields from master page over the report. The total page shows the correct value; however, the current page always shows a value of one. Is there anything I need to setup to get it working correctly?
Thanks,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Page number and total page [message #1067972 is a reply to message #774451] |
Thu, 11 July 2013 09:47   |
Eclipse User |
|
|
|
I try to avoid everything page-numbering related with BIRT itself, as it is all buggy (e.g. it doesn't work at all with RunAndRenderTask, and separate RunTask and RenderTask breaks pagination...) (see e.g. a Bugzilla entry by yaytay).
Intead, we are using a PostProcessor:
The BIRT Report tells the PostProcessor where, in which format, and under which conditions the page numbering should be added.
This is a bit ugly when designing the report (as the position has to be fixed, e.g. it is impossible to do this in a flow text), but it is working fine for all the reports we developed until now.
Features:
BIRT can feed the PostProcessor with several of "PageNumberingInstructions".
Each one has the following information:
- Font (Name, Bold?, Italic?, ptSize)
- Format e.g. "Page {0} of {1}"
- Rect (absolute position on the page in PDF units)
- Alignment Left/Right/Center
- Condition as a Javascript expression, e.g. "page==1" or "page>1"
- ResetAtLevel (optional)
As a special feature, the PostProcessor uses the PDF Outline (Table-of-Contents in BIRT-speech) to find out about grouping information. Inside the Format and the Condition, the PostProcessor can use this information.
With "ResetAtLevel", you can reset the page numbering to 1 whenever a TOC entry of the given level (or lower) changes.
With "{2}" in the Format, you can display the Outline/TOC Root (level 0) text, with "{3}", you can display the current text for TOC level 1, "{4}" is the current TOC level 2 text and so on.
This allows a "grouped page numbering".
E.g. if the TOC is like this:
My Report physical page
Preface 1 .. 3
Chapter 1 4 .. 8
Section 1 4 .. 6
Section 2 7 .. 8
Chapter 2 9 .. 10
Section 1 9
Section 2 9 .. 10
Say, you want the page-numbering only for the actual content, not for the preface, and it should show only the page inside the current chapter in the page header.
You also want to display the current Chapter and Section centered in the page footer.
Then you could use this:
// First instruction, for the Page-Numbering
.Font = ...;
.Format = "Page {0} of {1}";
.Rect = ...;
.ResetAtLevel = 1; // for each chapter
.Condition = "context[1].substring(0,6) == 'Chapter'";
// Inside the preface, this is false, while true inside the chapters
// Next instruction, for the current Chapter and Section text
.Font = ...;
.Format = "{3} - {4}";
// {2} is TOC context level 0 (My Report), {3} is TOC context level 1 (Chapter ...)
// and so on
.Rect = ...;
.Condition = "context[1].substring(0,6) == 'Chapter'";
// Inside the preface, this is false, while true inside the chapters
If anyone is interested, please contact me via www.t-p.com (ask for Henning)
Of course it would be better if BIRT supported this out of the box...
[Updated on: Thu, 11 July 2013 09:48] by Moderator
|
|
|
Re: Trick for total page count in BIRT PDF !!!!!!!! [message #1385345 is a reply to message #774451] |
Thu, 05 June 2014 14:14  |
Eclipse User |
|
|
|
Basically total page doesn't work with BIRT API.
Trick to get the pagecount
1:First generate the PDF (temporary pdf)
2: Calculate the total pages and send it as report parameter and use it in final pdf
sample code
public StreamedContent getFile() {
DefaultStreamedContent file = null;
InputStream stream = null;
try {
stream = generateSoapNotePdf(null);
PdfReader reader = new PdfReader(stream);
int pageCount = reader.getNumberOfPages();
reader.close();
stream = generateSoapNotePdf(""+pageCount);
file = new DefaultStreamedContent(stream, "application/pdf",
"encounterSOAP.pdf");
return file;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public InputStream generateSoapNotePdf(String pageCount) {
List<ReportParameter> parameters = new ArrayList<ReportParameter>();
parameters.add(new ReportParameter("encounterId", this.encounter
.getId().toString()));
parameters.add(new ReportParameter("pageCount", pageCount));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
reportingService.generateReport("encounterSOAP.rptdesign",
Report.RENDER_PDF, parameters, bos);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e);
}
InputStream stream = new ByteArrayInputStream(bos.toByteArray());
return stream;
}
|
|
|
Powered by
FUDForum. Page generated in 0.45953 seconds