Jump to content
JasperReports Library 7.0 is now available ×

2 page report - portrait v/s landscape


prashanth.talkad

Recommended Posts

hi, i'm trying to get a two page report, one in landscape and one in portrait mode. can i achieve this with a cingle jrxml? like for example if the two pages are, lets say details of a person on one page(portrait) and a certificate for the person for passing his certification in the other page(landscape).

i've currently designed the report in a single jrxml with a single query to populate the fields in both the pages since both pages have similar fields like name, date and the like.

any help is appreciated.

thanks,

p

Link to comment
Share on other sites

  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

prashanth.talkad wrote:

can i achieve this with a cingle jrxml?

 

You can't, all the pages produced by a single report have the same size and orientation.

 

The only thing you could do is to design two reports and use batch exporting to produce a single output file.

 

Regards,

Lucian

Link to comment
Share on other sites

thanks for clarifying Lucian !

I've re-designed my reports to include batch exporting via 2 JasperPrint objects and feeding them to the JRPdfExporter list.

 

I've uploaded the portrait and landscape.jrxml's into JasperServer.

 

Scenario::

The query returns more than one row. Lets say "n" rows.

 

When I run the report via the java application, it always prints the "n" portrait pages and then prints the landscape format.

What I'd like to see is that it prints the portrait and landscape reports printed alternatively - it augurs well for the end user as well!

any help lucian? :) thanks

Link to comment
Share on other sites

here's my code for the report generation - please lemme know if there is any parameter i'm missing here that might print portrait and landscaped reports alternatively rather than all portraits first and then all landscapes :((

 

File pdfFile = File.createTempFile("ABC", ".pdf");

 

Map<String, Object> parameters = new HashMap<String, Object>();

parameters.put(JASPER_REPORT_PARAMETER_NAME1, JASPER_REPORT_ID);

parameters.put(JASPER_REPORT_PARAMETER_NAME2, getID());

 

JasperPrint reportPortrait = jasperServerReportDao.generateReport(JASPER_REPORT_PORTRAIT_URI, parameters);

JasperPrint reportLandscape = jasperServerReportDao.generateReport(JASPER_REPORT_LANDSCAPE_URI, parameters);

 

JRPdfExporter exportMergedReport = new JRPdfExporter();

List list = new ArrayList();

list.add( reportPortrait );

list.add( reportLandscape );

 

exportMergedReport.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, list);

exportMergedReport.setParameter(JRPdfExporterParameter.OUTPUT_FILE, pdfFile);

 

exportMergedReport.exportReport();

 

thanks!

Link to comment
Share on other sites

prashanth.talkad wrote:

When I run the report via the java application, it always prints the "n" portrait pages and then prints the landscape format.
What I'd like to see is that it prints the portrait and landscape reports printed alternatively - it augurs well for the end user as well!

 

Batch exporting always works by processing the JasperPrint objects in the order in which they appear in the JASPER_PRINT_LIST collection. If you need to interleave pages of the two reports, you will need to manually split the reports into JasperPrint objects that contain a single page, or come up with custom exporters that do this automatically.

 

Regards,

Lucian

Link to comment
Share on other sites

lucian

i used the getPages() method in JasperPrint and tried to loop through the list of pages alternatively between the portrait and landscapes but i encounter an exception when I call "exportMergedReport.exportReport();" - ClassCastException - JRBasePrintPage....

 

ne comments?

 

my code is below:

 

JasperPrint reportCoverLetterInPortraitMode = jasperServerReportDao.generateReport(JASPER_REPORT__PORTRAIT_URI, parameters);

JasperPrint reportCertificateInLandscapeMode = jasperServerReportDao.generateReport(JASPER_REPORT_LANDSCAPE_URI, parameters);

 

JRPdfExporter exportMergedReport = new JRPdfExporter();

List coverLetters = reportCoverLetterInPortraitMode.getPages();

List certificates = reportCertificateInLandscapeMode.getPages();

 

List list = new ArrayList();

 

for(int i=0; i<coverLetters.size(); i++){

list.add(coverLetters.get(i));

list.add(certificates.get(i));

}

exportMergedReport.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, list);

exportMergedReport.setParameter(JRPdfExporterParameter.OUTPUT_FILE, pdfFile);

 

exportMergedReport.exportReport();

 

thanks,,,,,,:)

Link to comment
Share on other sites

You can't simply put report pages in JASPER_PRINT_LIST because, as the name and the documentation say, the parameter is a list of JasperPrint objects. You need to wrap each page in a JasperPrint instance.

 

You can do something like

Code:

protected List createPageJasperPrints(JasperPrint report) throws JRException {
//fetch report pages
List pages = new ArrayList(report.getPages());
//remove all pages from the report
for (int idx = pages.size() - 1; idx >= 0; --idx) {
report.removePage(idx);
}
//quick way to clone JasperPrint attributes
byte[] reportTemplateXml = JasperExportManager.exportReportToXml(report).getBytes();
List reports = new ArrayList(pages.size());
for (Iterator it = pages.iterator(); it.hasNext();«»)
{
JRPrintPage page = (JRPrintPage) it.next();
//create a page report
JasperPrint pageReport = JRPrintXmlLoader.load(new ByteArrayInputStream(reportTemplateXml));
pageReport.addPage(page);
reports.add(pageReport);
}
return reports;
}

...

List pageReports1 = createPageJasperPrints(report.print);
List pageReports2 = createPageJasperPrints(report2.print);
//merge the two lists
List pageReports = new ArrayList(pageReports1.size() + pageReports2.size());
for (Iterator it1 = pageReports1.iterator(), it2 = pageReports2.iterator();
it1.hasNext() || it2.hasNext();«») {
if (it1.hasNext()) {
pageReports.add(it1.next());
}
if (it2.hasNext()) {
pageReports.add(it2.next());
}
}

JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, pageReports);

 

HTH,

Lucian

Link to comment
Share on other sites

when I try to parse the xml via the JRPrintXmlLoader, the prepareDigester() method in the class seems to throw a VerifyError -

 

Caused by: java.lang.VerifyError: (class: net/sf/jasperreports/engine/xml/JRPrintXmlLoader, method: prepareDigester signature: ()Lnet/sf/jasperreports/engine/xml/JRXmlDigester;) Incompatible argument to function

 

The line that throws the error is::::

JasperPrint pageReport = JRPrintXmlLoader.load(new ByteArrayInputStream(reportTemplateXml));

 

Is there something I'm missing here?

 

thanks

Link to comment
Share on other sites

prashanth.talkad wrote:

Caused by: java.lang.VerifyError: (class: net/sf/jasperreports/engine/xml/JRPrintXmlLoader, method: prepareDigester signature: ()Lnet/sf/jasperreports/engine/xml/JRXmlDigester;) Incompatible argument to function

 

This sounds like a JVM error. Does this happen in the latest JVM from Sun?

 

Regards,

Lucian

Link to comment
Share on other sites

hi, my jdk version is 1.5.0_12 and jre 1.5.0_12(i also have the jre1.6.0_03). i'm developing using netbeans 6.0 with the visual web pack extension.

not sure why its not able to recognise the digester - i downloaded the digester jar as well and put it in my lib folder - commons-digester-1.8.jar

Post edited by: prashanth.talkad, at: 2008/03/25 04:12

Link to comment
Share on other sites

I don't know why the JVM throws that exception. Does this happen in NetBeans only, or when running the stand alone application as well?

 

You could workaround this by serializing and deserializing the JasperPrint object instead of using the XML exporter and JRPrintXmlLoader.

 

Regards,

Lucian

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...