Hi!
I need get the number of pages printed in jasper in a specific report and save this number.
If someone have a example or where could I find a example.
Thanks.
I use:
Servoy 4.1.5 - build 687
Postgresql 8.3
jasperreports-3.7.1 + IReport 3.7.1
This is a pure Java aproach:
Generate your report. Save it as JasperPrint.
Open the JasperPrint in your code something like:
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(fileName);
JasperPrint jp = JasperFillManager.fillReport(jasperReport, parameters, ConnectToDatabase.getConnection());
int pagesCount = jp.getPages().size();
Another Way round would be to create a scriptlet.
You could write a scriptlet which gets called at the end of the ReportGeneration. For example place the call in the summary Band.
Whe the scriptlet is called, you retrive the Variable Value of pageNumber, and write it to the database.
eg.
package de.oscomputing.tableOfContent;
/**
*
* @author Jan
*/
import java.io.File;
import java.util.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.util.JRLoader;
public class HeadingScriptlet extends JRDefaultScriptlet
{
public String Caller() throws JRScriptletException
{
Integer pageindex = (Integer)this.getVariableValue("PAGE_NUMBER");
//implement your save to database function
}
}
in iReport add the FULLY QUALLYFIED NAME!! as ReportScriptlet. For this case, it would be:
de.oscomputing.tableOfContent
then place a field in the summary band.
Click on EditExpression. There in the Parameter Section click Parameter: REPORT_SCRIPTLET, there you will see your implemented method of the scriptlet.
Happy Coding!
Jan
Hi Jan! many thanks for the help!!! ![Mr. Green :mrgreen:]()
when you talk about “FULLY QUALLYFIED NAME” you make reference to “CLASSPATH” in option in iReport (Tools → Options → iReport → Classpath). I do not understand what you mean.
something else, know how to change the language of iReport 3.7.2???
Thanks!!!
As for your 1st question “Fully Qualified Name”:
- You create a Scriptlet.
- you Export it as *.jar file, for Example MyScriptlet.jar
- you add the MyScriptlet.jar to the classpath in Ireport.
- Now for the fully qualified name. If your package where the Scriptlet lies is named eg. com.myscriptlet and the scriptlet is called MyFirstScriptlet you have to add in Ireport in the ReportScriptlet Property “com.myscriptlet.MyFirstScriptlet”
the fully qualified Name does NOT accord to name of the. Only to the Package And Class Names in the jar.
Also have a look at this Thread:
http://www.servoy.com/forum/viewtopic.php?f=15&t=13585
As for the second one:
In the ReportInspector mark the Report.
In the Property Window you can now change the Language from Groovy(Which is default since iReport 3.5.x I think ) to Java. Reports with Groovy will not work properly in combination with the JasperReport Plugin for Servoy.
Hope this helps!
Cheers
Jan
GevatterTod:
As for your 1st question “Fully Qualified Name”:
- You create a Scriptlet.
- you Export it as *.jar file, for Example MyScriptlet.jar
- you add the MyScriptlet.jar to the classpath in Ireport.
- Now for the fully qualified name. If your package where the Scriptlet lies is named eg. com.myscriptlet and the scriptlet is called MyFirstScriptlet you have to add in Ireport in the ReportScriptlet Property “com.myscriptlet.MyFirstScriptlet”
the fully qualified Name does NOT accord to name of the. Only to the Package And Class Names in the jar.
Also have a look at this Thread:
http://www.servoy.com/forum/viewtopic.php?f=15&t=13585
Good!! I create my .jar file, but when compile the report this error occurs:
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
- java.lang.ClassNotFoundException: com.lyo.saveNumPagesScriptlet
package com.lyo;
import java.io.File;
import java.util.*;
import lyo.jdbc.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.util.JRLoader;
public class saveNumPagesScriptlet extends JRDefaultScriptlet {
public String Caller() throws JRScriptletException {
Integer pageindex = (Integer)this.getVariableValue("PAGE_NUMBER");
//my implement to save in database
As for the second one:
In the ReportInspector mark the Report.
In the Property Window you can now change the Language from Groovy(Which is default since iReport 3.5.x I think ) to Java. Reports with Groovy will not work properly in combination with the JasperReport Plugin for Servoy.
I referred to the language of iReport IDE, my OS is in Italian but I want to have iReport in English ![Confused :?]()
thanks for your time Jan!!
Did you add the jar to the classpath?
If so, did you Restart iReport after adding the jar to the classpath?
GevatterTod:
Did you add the jar to the classpath?
If so, did you Restart iReport after adding the jar to the classpath?
yes I did it!!
these are my test files http://www.easy-share.com/1909987695/myscriptlet.rar
Looks like your jar is strange.
Try to make the Classpath:
E:.java.com.lyo
according to the directories in your jar, this should be the classpath.
you should also include the neccessary drivers and classes you need for writing the pageNumbers to the database in the jar.
Hope this helps.
Jan
MyScriptlet.jar (1.83 KB)