views:

457

answers:

2

I've been trying to use JasperReports to print in a resolution above 72dpi, with no success.

I need to use some resolution above 72dpi because I'm going to print in those pre-formatted adhesive labels, which need a certain level of precision when setting the positions. But, as JasperReports can only use pixels, and AFAIK only supports the 72dpi configuration, I can't set the margins, spacings, etc correctly.

For instance, when you need a 1mm configuration, you need to convert to pixels, which would be 3px as automatically converted by iReport (actually, the real value is ~ 3.78px, but pixel can't be decimal and iReport truncates instead of rounding it). But, when you calculate it back to mm (when you print, for example), it actually gets a size of ~ 0.79mm, not the old 1mm you needed. If considering the round value (4px instead of 3px), you would have a final printed value of ~ 1.06mm, still wrong.

Even if you think 0.06mm or 0.21mm isn't something valuable, it actualy IS when you have 20 or more sequenced labels, and this margin of error gets bigger as soon as you increase the number of labels.

Finally, is there any way I can use JasperReports to print reports with a milimetric precision or is there any workaround for this problem?

A: 

Try

PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
attrs.add(new PrinterResolution(203, 203, ResolutionSyntax.DPI));

printerExporter.setParameter(
    JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, attrs);

(from here)

Bozho
Thanks for the answer, but I couldn't get it to work. I was able to achieve a similar solution, which I'm going to post now. But the "official" DPI solution would be better, if I just could figure out how to make it work.
Renato
A: 

What did work as a kind of workaround was using JRGraphics2DExporterParameter.ZOOM_RATIO as the PrinterExporter parameter, with the proper zoom ratio as float.

For example, suppose I have a 144dpi configuration (2 x 72dpi), the above ZOOM solution worked if I passed 0.5f as parameter, because it prints the 72dpi equivalent size.

Considering it is a workaround, a real DPI solution would be aprecciated.

Renato