[#11336] - The report does not export the correct data to Word table

Category:
Bug report
Priority:
Normal
Status:
Feedback Requested
Project: Severity:
Minor
Resolution:
Open
Component: Reproducibility:
Always
Assigned to:

Hello.

I have a problem when I am trying to export a report to Word, the reports show the correct data on web service, but when I export data to Word (docx), I have text cutted in many cells. In Jaspersoft Studio I have configured the band split type to 'Prevent' and all band fields with stretch type 'Relative To Tallest Object'. I have tried to configure all band fields with padding but it does not work, What can I do? I add some pictures to show you the case.

Regards.

Dani.

AttachmentSize
Image icon word.png96.37 KB
v6.4.2
dmarin's picture
4
Joined: May 18 2017 - 4:21am
Last seen: 9 months 4 weeks ago

3 Comments:

#1
  • Resolution:Open» Suspended
#2
  • Resolution:Suspended» Open
  • Status:Acknowledged» Confirmed

Hello,

We stuck with the same problem, investigated it, and found the “incorrect pixels to points conversion” issue.

In JasperReports, all measures are stored in pixels. Pixels are device-dependent units. DOCX cell paddings are stored in twips (1/1440 inch). Twips are device-independent units.
When DOCX file is generated, JasperReports converts 1 px of each Border Paddings measure to 1 pt (20 twips) of Word table cell paddings measure. That causes vertical overflows of text as shown in the attached picture.

Assuming the 600 x 800 screen resolution and
1 horizontal px = 1 pt = 20 twips,
then
1 vertical px = 600/800 * 1 pt = ¾ pt = 15 twips.

For example, if we set Border Paddings for left, right, top and bottom to 4 px, these measures should be converted to Word table cell paddings so: left and right – 4 pt (80 twips); top and left – 3 pt (60 twips). After fixing that, the same text is displayed in Word table cells without cropping.
In Visual Basic, conversion between twips and screen pixels is achieved using functions such as TwipsPerPixelX and TwipsPerPixelY.

We fixed this problem for our reports by overriding DocxBorderInfo class:

/**
* Overridden Jasper DocxBorderInfo class for fixing pixels to points conversion.
*/
public class OurDocxBorderInfo extends DocxBorderInfo {

public OurDocxBorderInfo(JRLineBox box) {
super(box);
borderPadding[TOP_BORDER] = String.valueOf(verticalPixelsToTwips(box.getTopPadding().intValue()));
borderPadding[BOTTOM_BORDER] = String.valueOf(verticalPixelsToTwips(box.getBottomPadding().intValue()));
}

public OurDocxBorderInfo(JRPen pen) {
super(pen);
}

private static int verticalPixelsToTwips(float pixels) {
return (int) (pixels * 15); // 1 vertical px = 3/4 pt = 20 twips/pt * 3/4 pt = 15 twips
}
}

AttachmentSize
Image icon docx_cell_paddings.png25.22 KB
#3
  • Status:Confirmed» Feedback Requested
  • Assigned:nobody» teodord

Hi,

You did not upload here any JRXML so that we can see what fonts you are using. Are you sure that the fonts you are using in the report template exist and are available to the JVM on the machine where the report is actually generated?
Chances are that you are designing your report on Windows, using Windows fonts, but your server runs on Linux/Unix where there fonts do not exist and are replaced with some other default fonts having different metrics.

For pixel perfect results, you need to control your fonts and provide them to the server using JasperReports font extensions. Jaspersoft Studio can help with that.

Thank you,
Teodor

Feedback
randomness