set page size in jasper reports

0
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
technotrans's picture
Joined: Aug 7 2007 - 11:10pm
Last seen: 11 years 9 months ago

7 Answers:

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

HTH,
Lucian
lucianc's picture
7055
Joined: Jul 17 2006 - 1:10am
Last seen: 8 hours 55 min ago
1
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!
rayzz04's picture
14
Joined: Jan 8 2008 - 10:42pm
Last seen: 11 years 4 months ago
1
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.

Regards,
Lucian
lucianc's picture
7055
Joined: Jul 17 2006 - 1:10am
Last seen: 8 hours 55 min ago
0
hello lucian...
i'm still facing the same problem with my thermo printer. does jasper send a form feed after the print-job is done? the printer always performs a feed when the print-job is done...
technotrans's picture
Joined: Aug 7 2007 - 11:10pm
Last seen: 11 years 9 months ago
0
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.

Regards,
Lucian
lucianc's picture
7055
Joined: Jul 17 2006 - 1:10am
Last seen: 8 hours 55 min ago
0
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
Code:
JRPrinterAWT.initPrinterJobFields(printerJob);<br />
                        <br />
// [added code]<br />
JasperPrint jPrint = (JasperPrint) parameters.get(JRExporterParameter.JASPER_PRINT);<br />
Paper paper = new Paper();<br />
PageFormat format = new PageFormat();<br />
if (jPrint.getOrientation() == JRReport.ORIENTATION_LANDSCAPE) {<br />
    format.setOrientation(PageFormat.LANDSCAPE);<br />
    paper.setImageableArea(0,0,jPrint.getPageHeight(), jPrint.getPageWidth());<br />
    paper.setSize(jPrint.getPageHeight(), jPrint.getPageWidth());<br />
} else {<br />
    format.setOrientation(PageFormat.PORTRAIT);<br />
    paper.setImageableArea(0,0,jPrint.getPageWidth(), jPrint.getPageHeight());<br />
    paper.setSize(jPrint.getPageWidth(), jPrint.getPageHeight());<br />
}<br />
format.setPaper(paper);<br />
<br />
printerJob.setPrintable(this, format);<br />
// [/added code]<br />
<br />
// determining the print service only once<br />
PrintService selectedService = (PrintService) parameters.get(JRPrintServiceExporterParameter.PRINT_SERVICE);</td></tr></tbody></table><br />
<br />
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.<br />
<br />
Chris<br>Post edited by: hirtz, at: 2008/03/12 17:05
hirtz's picture
2
Joined: Mar 12 2008 - 1:02am
Last seen: 11 years 2 months ago
0
/snip

maybe, just maybe one copy will do.

Chris
Post edited by: hirtz, at: 2008/03/12 17:05
hirtz's picture
2
Joined: Mar 12 2008 - 1:02am
Last seen: 11 years 2 months ago
Feedback
randomness