Jump to content
We've recently updated our Privacy Statement, available here ×

Setting Page Orientation at Runtime


markrgli

Recommended Posts

Hi guys,

I have some reports where the page orientation is determined by some user input. The report design files (jrxml) use a portrait orientation but I need to be able to change them before the reports are generated. I have the code that sets the page orientation but it doesn't seem to be working.

Any ideas on this one?

Thank you in advance.

Code:


Post Edited by markrgli at 04/28/2009 02:44
Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Changing the orientation on the JasperPrint object does not change the width or height of the generated pages.  In order to do that you'd need to do it before filling the report, i.e. on the JasperDesign object (which would then need to compile).

Regards,

Lucian

Link to comment
Share on other sites

  • 1 year later...

 Hello Lucian,

 

Can you please let me know in detail what I need to do. I stuck with the same problem. I have 6 subreports.  4 of them need to be printed in portrait and remaining in landscape. Can you please let me know how to do it ?

Thanks in advance.

 

Regards,

-Sujan

Link to comment
Share on other sites

Hi Sujan,

 

I attached the code I used to solve the problem. I hope it will be useful to you.

 

Regards,

Mark

 

sujan
Wrote:

 Hello Lucian,

 

Can you please let me know in detail what I need to do. I stuck with the same problem. I have 6 subreports.  4 of them need to be printed in portrait and remaining in landscape. Can you please let me know how to do it ?

Thanks in advance.

 

Regards,

-Sujan

Code:
public static void setPageSizeAndOrientation(JasperDesign design, ReportConfig config) {        // ReportConfig, PaperInfo.Size, PaperInfo.Orientation are custom classes/enums	PaperInfo.Size size = ReportBuilder.getPaperSize(config);	PaperInfo.Orientation orientation = ReportBuilder.getOrientation(config);	if (size == PaperInfo.Size.LEGAL) {		// Size of Legal is 8.5x14 in. At 72dpi, this translates to		// 8.5*72x14*72 = 612x1008.		if (orientation == PaperInfo.Orientation.LANDSCAPE) {			design.setPageWidth(1008);			design.setPageHeight(612);		} else {			design.setPageWidth(612);			design.setPageHeight(1008);		}	} else if (size == PaperInfo.Size.LETTER) {		// Size of Letter is 8.5x11 in. At 72dpi, this translates to		// 8.5*72x11*72 = 612x792.		if (orientation == PaperInfo.Orientation.LANDSCAPE) {			design.setPageWidth(792);			design.setPageHeight(612);		} else {			design.setPageWidth(612);			design.setPageHeight(792);		}	} else {		// Default is A4.		// Size of A4 is 8.27x11.69 in. At 72dpi, this translates to		// 8.27*72x11.69*72 = 595x842.		if (orientation == PaperInfo.Orientation.LANDSCAPE) {			design.setPageWidth(842);			design.setPageHeight(595);		} else {			design.setPageWidth(595);			design.setPageHeight(842);		}	}}
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...