Jump to content
Changes to the Jaspersoft community edition download ×

How to change margins after loading a report?


2005 IR Help

Recommended Posts

By: C-Box - c-box

How to change margins after loading a report?

2004-05-05 01:28

Hi,

 

Is there a way to adjust the left and the upper margin after loading a compiled report?

 

here my plan:

1.) Load a compiled report from file/stream with JRLoader

2.) let the user choose a printer (every printer has its own special slightly margins-settings but has the same business-paper with preprinted logo)

3.) now read out the special margins for the choosen printer (e.g. a OffSet X and OffSet Y is stored in database for each printer) and adjust the little pixelchanges to the loaded report margins (left and top).

4.) print the loaded report

 

It's import to move the whole report a little bit more left or right and more down or up to fit the report-design to the preprinted business-paper.

 

All I found is that I can set the margins in a JRDesign-Object but that need to get compiled again what takes too much time because of it's technique with storing a .JAVA to a temp-folder and read it to stream and so on.

 

Has anybody a solution for what I wanna do?

 

tia

C-Box

 

 

 

 

By: C-Box - c-box

RE: How to change margins after loading a report?

2004-05-06 07:53

Yes that's the point, it takes to much time recompiling the whole report just because of moving it 2 pixel right or left.

And it also a quicker way to solve that problem. My reports are quite complex and iterating each element of each band takes probably more time that the global OffSet-Variables.

 

I hope I needn't recode my changes with the next release.

 

C-Box

 

 

 

 

By: juozas salna - pukomuko

this method works!

2004-05-10 04:59

thanks very much

 

 

 

 

By: C-Box - c-box

RE: How to change margins after loading a report?

2004-05-06 04:09

Hmmm no reply... then probably impossible --> then DoItYourSelf :-)

 

here the reason:

 

Sometimes it's very important to move the WHOLE report a bit more left and down (or perhaps just more right ...) especially when printing on business-paper with preprinted logos. Because each printer has it's own margins and a ACCURATE positioning is required.

You could change the margins of the report-layout... but therefore a recompiling is necessary for revalidation of the report-layout.

But that again takes too much time and isn't required really.

 

here the way:

Introducing a global OffSetX and OffSetY that is added to the routine that places the elements on the print-object that is finally send to the printer.

 

here the changes:

 

---> JRAbstractExporter.java <---

 

/** !!!Start!!! new inserted code by C-Box -> it could be, that some "import lines" must be added (but that's quickly done with IDE)

* Two new attributes that contains global OffSet for X and Y to move ALL elements more left/right and/or up/down

*/

 

protected int offSetX = 0;

protected int offSetY = 0;

 

// !!!End!!! new inserted code by C-Box

 

then right in the starting of the "setInput()"-Method that lines:

 

** !!!Start!!! new inserted code by C-Box -> it could be, that some "import lines" must be added (but that's quickly done with IDE)

* Two new attributes that contains global OffSet for X and Y to move ALL elements more left/right and/or up/down

*/

Integer offSetX = (Integer)parameters.get(JRExporterParameter.OFFSETX);

if (offSetX != null)

{

this.offSetX = offSetX.intValue();

}

Integer offSetY = (Integer)parameters.get(JRExporterParameter.OFFSETY);

if (offSetY != null)

{

this.offSetY = offSetY.intValue();

}

// !!!End!!! new inserted code by C-Box

 

----- that's all in JRAbstractExporter.java ------

 

now the ---> "JRExporterParamter.java" <---

 

/** !!!Start!!! new inserted code by C-Box -> it could be, that some "import lines" must be added (but that's quickly done with IDE)

* Two new attributes that contains global OffSet for X and Y to move ALL elements more left/right and/or up/down

*/

public static final JRExporterParameter OFFSETX = new JRExporterParameter("OffSetX");

public static final JRExporterParameter OFFSETY = new JRExporterParameter("OffSetY");

// !!!End!!! new inserted code by C-Box

 

----- that's all in JRExporterParameter.java ------

 

now the ---> "JRPrintServiceExporter.java" <---

 

in the "exportReport()"-Method when setting the new exporter after adding "ProgressMonitor"....

 

/** !!!Start!!! new inserted code by C-Box -> it could be, that some "import lines" must be added (but that's quickly done with IDE)

* Two new attributes that contains global OffSet for X and Y to move ALL elements more left/right and/or up/down

*/

exporter.setParameter(JRExporterParameter.OFFSETX, new Integer(offSetX));

exporter.setParameter(JRExporterParameter.OFFSETY, new Integer(offSetY));

// !!! End!!! new inserted code by C-Box

 

----- that's all in JRPrintServiceExporter.java ------

 

and last but not least the ---> "JRGraphics2DExporter.java" <---

 

it's just within the "exportPage" Method within the For-Loop (after line 244 in release 0.5.2):

 

element = (JRPrintElement)it.next();

/** !!!Start!!! new inserted code by C-Box -> it could be, that some "import lines" must be added (but that's quickly done with IDE)

* Two new attributes that contains global OffSet for X and Y to move ALL elements more left/right and/or up/down

* Here add the global OffSet for X and Y

*/

element.setX(element.getX()+offSetX);

element.setY(element.getY()+offSetY);

// !!!End!!! new inserted code by C-Box

 

----- that's all in JRGraphics2DExporter.java ------

 

here the usage (example):

 

JRPrintServiceExporter exporter = new JRPrintServiceExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OFFSETX, new Integer(10));

exporter.setParameter(JRExporterParameter.OFFSETY,new Integer(50));

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,printRequestAttributeSet);

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,printServiceAttributeSet);

exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,Boolean.FALSE);

exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,Boolean.TRUE);

try {

exporter.exportReport();

} catch (JRException je) {

System.out.println("Error while printing the report:n" + je.getMessage());

}

 

then the WHOLE report is moved 10 pixel left and 50 pixel down (with the sample values)... so a accurate positioning is now possible.

On every workstation could so the individually offSet-Settings stored in e.g. a DataBase and called before printing or the user can adjust them right before printing the report (without recompiling, refilling it)

 

I will post that to requested features list .... perhaps Teodord could take a eye on it.

 

C-Box

 

 

 

 

By: Ashish - ashisharte

RE: How to change margins after loading a rep

2004-05-06 07:04

Additionally, you can define a key for each element.

While compiling you can get the handle ( JRElement ) to this field and adjust the position of this field. Thats how I do it.

But yes this requires recompilation at runtime.

 

-Ashish

 

 

 

 

By: Teodor Danciu - teodord

RE: How to change margins after loading a rep

2004-11-21 12:54

 

Hi,

 

This feature was added to the CVS repository version

and will be part of the next release.

 

Thank you,

Teodor

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...