Jump to content

set page size in jasper reports


Recommended Posts

hi there...


I want to print a report on a thermo transfer printer and i think i have to specify the dimensions of the label so that so printer makes a feed to the correct position.


The JasperPrint-Object has the methods setPageHeight(int h) and setPageWidth(int w). But what kind of dimension i have to specify in there? Is it mm or inch or pixel? Is it the right place at all?


!!! HELP !!! :ohmy:

Post edited by: technotrans, at: 2007/12/06 13:54

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

If you want a report having pages of a specific size, you should set the pageWidth and pageHeight attributes of the report template (JRXML). The attribute values are pixels, and JasperReports uses 72 dpi (i.e. pageWidth="72" means that the page will be 1 inch wide).




Link to comment
Share on other sites

  • 1 month later...
Hi! If JP uses 72 dpi, then a standard A4(8.5" x 11") size document's height should be 72*11? I used the length 842 as well as I've seen on many google searches, and none of these work. I've even taken the height attribute out, and still doesnt work. It seems there is a max height value built into JP. The page's footer keeps printing much before the next page and then the next page starts on the first and this continues throughout the document I'm creating. Please help!
Link to comment
Share on other sites

First of all, 8.5" x 11" is not A4, but US Legal.


The page footer will print at a location determined by the page height declared in the JRXML (and if you don't declare a page height, 842 will be used), and not at the bottom of the psychical page on which the report gets printed.


It's not very clear what you are doing and how you're expecting JasperReports to work, you may want to describe your issue better.




Link to comment
Share on other sites

  • 1 month later...

JasperReports uses the Java AWT print APIs to print a report as a pageable document. This makes perfect sense in the JR context, since JR reports are paginated documents. I assume that the AWT print classes issue a form feed after each printed page.


If you need a different printing mechanism, you could implement it externally to JR or post a JR feature request.




Link to comment
Share on other sites

  • 3 weeks later...

technotrans wrote:

does jasper send a form feed after the print-job is done? the printer always performs a feed when the print-job is done...


Facing sort of the same problem printing labels on fanfold paper(5x2" per label, 6 per "sheet") using a dot matrix printer we have come up with the following workaround/fix in JRPrintServiceExporter. We are still using jasperreports 1.3.3 but the problem seems to still exist with 2.04 and the "patch" should work as well(not much changed in that context as far as i know).


As activating my jasperforge account generates an error message you'll have to live with a bit of code posted here for now.


JRPrintServiceExporter.java, lines 133 and following


// [added code]
JasperPrint jPrint = (JasperPrint) parameters.get(JRExporterParameter.JASPER_PRINT);
Paper paper = new Paper();
PageFormat format = new PageFormat();
if (jPrint.getOrientation() == JRReport.ORIENTATION_LANDSCAPE) {
paper.setImageableArea(0,0,jPrint.getPageHeight(), jPrint.getPageWidth());
paper.setSize(jPrint.getPageHeight(), jPrint.getPageWidth());
} else {
paper.setImageableArea(0,0,jPrint.getPageWidth(), jPrint.getPageHeight());
paper.setSize(jPrint.getPageWidth(), jPrint.getPageHeight());

printerJob.setPrintable(this, format);
// [/added code]

// determining the print service only once
PrintService selectedService = (PrintService) parameters.get(JRPrintServiceExporterParameter.PRINT_SERVICE);


This might as well(maybe even better) be added line 185 and following inside the loop instead but extensive testing generated exactly the results we expected so for now this works fine for us.



Post edited by: hirtz, at: 2008/03/12 17:05

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