Landscape and Portrait layout in same report

2
Is this possible? I have seen on the forumns that people were unable to do it unless they used a tool in iText to merge the pages, but with page numbering this really isn't a good way to do it.

My context is that my report is of a known format...

Page 1 : (Portrait) covering letter
Page 2 : (Portrait) summary page (user details summary, not data summary)
Page 3, 4, etc: (Portrait) "Dynamic data in detail section
Page n: (Landscape) Final summary page, in landscape (this page has to be in landscape, will not fit in portrait in asthetic fashion). Has a chart or two and some images etc.

I am hoping that there is an easy way to have the required pages be in alternating orientations without having to use an external tool. The report is integrated into a website using a hibernate datasource and I am hoping to avoid having any overhead or extra work incurred outside the report (i.e. needing to use iText to merge documents etc)

Any comments on this issue are appreciated (including the best workarounds possible should it not be possible).

Thx,
Rob
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 14 years 8 months ago

9 Answers:

0
I'm having the same exact problem. Looking around I found this on the forums...

By: jj1978 - jj1978
RE: Using portrait and landscape in single report
2006-05-21 18:18
Yes it is possible!

eg: My report page 1 (jr1) is portrait and page 2 (jr2) landscape.

JasperReport jr1 = (JasperReport)JRLoader.loadObject( ... );
JasperReport jr2 = (JasperReport)JRLoader.loadObject( .... );

JREmptyDataSource ds = new JREmptyDataSource( 1 );

JasperPrint print1 = JasperFillManager.fillReport( jr1, new HashMap(), ds );
ds.moveFirst();
JasperPrint print2 = JasperFillManager.fillReport( jr2, new HashMap(), ds );
List l = new ArrayList();
l.add( print1 );
l.add( print2 );
JRPdfExporter exp = new JRPdfExporter();
exp.setParameter ( JRExporterParameter.JASPER_PRINT_LIST, l );
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, SAVE_LOCATION );
exp.exportReport();

I cannot seem to get this to work with JRPrintServiceExporter as of yet for actual printing (it prints only the first jasperReport, then fails to print the rest in the list), however you might have some luck with it.

If you find another solution or someone can help it would be much appreciated. Thanks.
enderfake's picture
Joined: Sep 26 2006 - 12:49pm
Last seen: 14 years 6 months ago
0
Hi,

JasperPrint objects do not support mixed page format.
So the only solution would be the batch export functionality mentioned.

I hope this helps.
Teodor
teodord's picture
5177
Joined: Jun 30 2006 - 9:00am
Last seen: 2 months 9 hours ago
0

Thanks Teodor!

Edit:
To achieve multiple page layouts for reports I did 2 different methods..

1. No Post Editing Was Needed:
Used pure jasper, as described above:

Code:
jasperReport1 = JasperCompileManager.compileReport(ROOT_DIR + "report_one.jrxml"«»);
jasperReport2 = JasperCompileManager.compileReport(ROOT_DIR + "report_two.jrxml"«»);
 
Map customParameters = new HashMap(); 
jasperPrint1 = JasperFillManager.fillReport(jasperReport1, customParameters, ds);
System.out.println("Merging document");
jasperPrint2 = JasperFillManager.fillReport(jasperReport2, new HashMap(), new JREmptyDataSource(1));	  
JRPdfExporter exp = new JRPdfExporter();
 
List list = new ArrayList();
list.add( jasperPrint1 );
list.add( jasperPrint2 );
 
exp.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, list);
exp.setParameter(JRPdfExporterParameter.OUTPUT_FILE, pdfFile);
exp.exportReport(); 


2. Post Editing Required:
-e.g. To add page numbering in header.
-Used iText
) wrote a program to merge the pages and manually insert page numbering on the pages.

Code:
private static void mergeAndNumber() throws IOException, DocumentException {
	PdfReader readerOne = new PdfReader("c:\\file_one.pdf"«»);
 
        // we retrieve the total number of pages
        int nOne = readerOne.getNumberOfPages();
 
	PdfReader readerTwo = new PdfReader("c:\\file_two.pdf"«»);
 
        // we retrieve the total number of pages
        int nTwo = readerTwo.getNumberOfPages();
 
        int totalPages = (nOne + nTwo);
	System.out.println("Total number of pages: " + (nOne + nTwo));
        Rectangle psize = readerOne.getPageSize(1);
 
        float widthPort = psize.width();
        float heightPort = psize.height();
 
        // step 1: creation of a document-object
        Document document = new Document(psize, 50, 50, 50, 50);
 
        // step 2: we create a writer that listens to the document
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:\\file_combined.pdf"«»));
        document.open();
 
        // step 4: we add content
        PdfContentByte cb = writer.getDirectContent();
        PdfImportedPage importPage = null;
    	BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
 
        float pageNumXPos = widthPort;
        float pageNumYPos = heightPort;
 
    	for (int i = 1; i <= nOne; i++) {
        	document.newPage();
        	importPage = writer.getImportedPage(readerOne, i);
        	cb.addTemplate(importPage, 0,0);
 
        	cb.moveTo(400, 40);       	
            cb.beginText();
            cb.setFontAndSize(bf, 10);
            //cb.showText("Page " + i  + " of " + totalPages);        	
            cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Page " + i  + " of " + totalPages, pageNumXPos - 45, pageNumYPos - 55, 0);
            cb.endText();
        }
    	document.setPageSize(PageSize.A4.rotate());
 
        for (int i = 1; i <= nTwo; i++) {
        	document.newPage();
        	importPage = writer.getImportedPage(readerTwo, i);
        	cb.addTemplate(importPage, 0,0);
 
            cb.moveTo(400, 40);        
            cb.beginText();
            cb.setFontAndSize(bf, 10);
            cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Page " + (nOne + i)  + " of " + totalPages, pageNumYPos - 20, pageNumXPos - 60, 0);     	
            cb.endText();
        }
 
        document.close();       
}

Incidentally Teodor/Lucian, is this type of functionality on the horizon for jasper reports?

rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 14 years 8 months ago
0
To add some more complexity to this issue, I am integrating this report into an AppFuse/Spring framework. To achieve this integration I am thinking I will need to create a custom Spring JasperReportsPdfView which will do the manual merging of the pdf file into an output stream to be returned to the browser for download. Has anyone ever done anything similar?


Lucian/Teodor any word on having portrait and landscape pages in PDF and other exporters is going to make it into a release of Jasper anytime soon?

Thx,
Rob
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 14 years 8 months ago
0
After you do the manual merge, what about returning the stream to the browser when they click on a link, and have it be type/pdf for content. It is not a "preview" per se.. but may do the trick. That was going to be my approach once I reached that stage on this report/project.

HTH,
Robin
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 14 years 8 months ago
0
also, has anyone tried to interleave portrait and landscape pages - for example, if i have a report with 2 pages, one to be printed in portrait mode and the other in landscape mode - and the query returns N rows - for my design, its printing N portrait pages forllowed by N landscaped pages.
I wanna print interleaving portrait/landscaped pages thats easy when an end user prints the report. One way lucian suggested is to write my own exporter - which i dont have time for at this moment.
any other suggestions lucian?

thanks in advance.
prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 13 years 2 months ago
0

Hi,

 

It would be greate if you could log a request for enhancement on the project trackers. This would allow us to refine the requirement and come up with a solution that suits more people.

Please give as many real-world use case scenarios as possible, so that we better understand this need of having variable page layout and size, inside a document.

 

Why is that the batch exporter functionality already existing in JR is not enough?

 

Thank you,

Teodor

 

teodord's picture
5177
Joined: Jun 30 2006 - 9:00am
Last seen: 2 months 9 hours ago
0

Hi Lucian/Tedor,

As you said, this was the only solution to have mixed orientation report. I did the implementation as suggetsed here and get the report as expected in PDF format.

But when I tried the same using JRRtfExporter, I come across one issue. Although the data and formatting was exported successfully, but when I opened the report using Word, all the pages were in Portrait orientation.

If I manually changed the orientation of the particular page, reports looks fine with desired orientation. But as this can not be expected from the end user, can you give any suggestion to have correct output while using RTF export.

As requirement is very urgent, any help is higly appreiciated.

 

mukeshsheoran07's picture
Joined: Mar 6 2011 - 8:56pm
Last seen: 10 years 1 month ago
0
maruthu.u's picture
Joined: Jun 19 2019 - 4:17am
Last seen: 3 months 1 week ago
Feedback