Smig Posted April 23, 2008 Share Posted April 23, 2008 How can I modify the report margins through the API. It seems trivial and I did search the forums but I couldn't find this information. JasperPrint doesn't seem to have any method that would do this. My problem is that I'm using jasper to fill the data on some labels that are already printed. Since the correct positioning of that data to fit the labels is crucial, and since some printers start printing at slightly differet points (enough to ruin some allignements) I thought I could provide the user with the option of adding or subtracting from the margins to make up for those little nuances between printers. Link to comment Share on other sites More sharing options...
Smig Posted April 24, 2008 Author Share Posted April 24, 2008 I thought of a workaround for the top margin, by eliminating the margin and adding a band, then I would only need a method to change the band's height. Of course, I could not find such a method either and I would still be unable to change the left margin. Anyway, in the meantime, I realized that the problem might be the fact that I'm working with the compiled .jasper file and not the XML one. Is this the problem? I can't change this stuff on the .jasper file? Do I need to compile the report at runtime to do what I want to do? Link to comment Share on other sites More sharing options...
Smig Posted April 24, 2008 Author Share Posted April 24, 2008 I've also tried to use input parameters as margins, which would be supplied by my java app, but I also can't put that to work as iReport will then be unable to read the file. So, I'll need one of 3 solutions:1) a way to use a parameter as a margin value. I've tried replacing the value with <![CDATA[$P{LeftMargin}]]> but it didn't work.2) a way to change the xml file with an easy to use Jasper API so that I could compile it at runtime with the correct margins.3) a way to change the margins of a compiled .jasper file to change them as I show the report to the user. Sorry for all my replies... Link to comment Share on other sites More sharing options...
dnvsrikanth Posted April 24, 2008 Share Posted April 24, 2008 hi Smig You can get margin sizes through JRBaseReport object. I think this may be helpful to you DNV Srikanth Link to comment Share on other sites More sharing options...
Smig Posted April 24, 2008 Author Share Posted April 24, 2008 I can get them but I can't set them. I already know the original margins so I won't need to read them at all, all I need is a way to modify them. Thanks for the help though. Link to comment Share on other sites More sharing options...
lucianc Posted April 24, 2008 Share Posted April 24, 2008 You cannot change the page margins on compile or filled reports, this can only be done at report design time (in JasperDesign). If all you want to do is to set some offsets when printing a report, you should use the OFFSET_X and OFFSET_Y export parameters. Regards,Lucian Link to comment Share on other sites More sharing options...
Smig Posted April 25, 2008 Author Share Posted April 25, 2008 Thanks! About that offset tip though, could you provide me with a short sample or a link where I could find one. I've been looking around but it's hard to tell what I should do exactly. I don't seem to be able to use those offset parameters with JasperPrintManager and I need to print the report directly so, using export, the most straightforward way would be to export it to xml using those export parameters, import it back to a JasperPrint object and then carry on as usual... I have a feeling this is not the more direct route... I will also try to do it with JasperDesign but I'd rather not have to compile the template everytime. Link to comment Share on other sites More sharing options...
lucianc Posted April 25, 2008 Share Posted April 25, 2008 You will have to switch from JasperPrintManager to JRPrintServiceExporter, which offers more complex printing options. You would do something likeCode:JasperPrint print = ...;int offsetX = ...;int offsetY = ...;JRPrintServiceExporter exporter = new JRPrintServiceExporter();exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);exporter.setParameter(JRExporterParameter.OFFSET_X, offsetX);exporter.setParameter(JRExporterParameter.OFFSET_Y, offsetY);//set other export parameters, such asexporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, true);exporter.exportReport(); HTH,Lucian Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now