当我的一行报告对于单个页面来说太长时,它会在下一页继续,但是,如此图所示,边框会被切断。
有什么想法吗?
我正在使用JRPdfExporter
将报告导出为PDF。
更新:
DynamicReport dynamicReport;
...
fastReportBuilder.setPageSizeAndOrientation(Page.Page_A4_Landscape());
fastReportBuilder.setUseFullPageWidth(true);
//margin 50
fastReportBuilder.setMargins(MARGIN, MARGIN, MARGIN, MARGIN);
fastReportBuilder.setDefaultStyles(getTitleStyle(), null, getColumnHeaderStyle(), getColumnDetailsStyle());
private Style getColumnHeaderStyle() {
Style hStyle = new Style();
hStyle.setBorder(Border.THIN());
hStyle.setTransparent(false);
hStyle.setBackgroundColor(new Color(0, 142, 175));
hStyle.setTextColor(Color.WHITE);
hStyle.setHorizontalAlign(HorizontalAlign.CENTER);
hStyle.setVerticalAlign(VerticalAlign.MIDDLE);
hStyle.setFont(new Font(10, MY_FONT, false));
return hStyle;
}
private Style getColumnDetailsStyle() {
Style cStyle = new Style();
cStyle.setBorder(Border.THIN());
cStyle.setFont(new Font(10, MY_FONT, false));
cStyle.setVerticalAlign(VerticalAlign.TOP);
return cStyle;
}
答案 0 :(得分:0)
Border Artifacts in JasperReport PDF Designed with iReport 5.1.0给了我一个主意。
我最终扩展了JRPdfExporter。出于某种原因,当数据被剪切并在下一页上继续时,数据被切断的单元框边界的高度和底部在左边的相邻单元上是不匹配的。为了解决这个问题,我将存储前一个单元格边框数据,因此当它到达不匹配的单元格边框数据时,可以对其进行更正。
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import net.sf.jasperreports.engine.JRLineBox;
import net.sf.jasperreports.engine.JRPrintElement;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import java.awt.*;
public class CustomPdfExporter extends JRPdfExporter {
private float previousTop;
private float previousHeight;
private float prevY1;
private float prevY2;
private static final float FLOAT_ZERO = 0F;
protected void exportBox(JRLineBox box, JRPrintElement element) {
if (!isBoxVisible(box)) return;
pdfContentByte.setLineCap(PdfContentByte.LINE_CAP_PROJECTING_SQUARE);
float x1 = element.getX() + getOffsetX();
float y1 = jasperPrint.getPageHeight() - element.getY() - getOffsetY();
float x2 = element.getX() + getOffsetX() + element.getWidth();
float y2 = jasperPrint.getPageHeight() - element.getY() - getOffsetY() - element.getHeight();
Rectangle r = new Rectangle(x1, y2, x2, y1);
if (previousTop == r.getTop() && previousHeight != r.getHeight()) {
r.setBottom(prevY2);
} else {
prevY2 = y2;
prevY1 = y1;
previousHeight = r.getHeight();
previousTop = r.getTop();
}
int borderFlag = 0;
float lineWidth = 0;
Color lineColor = null;
if (box.getLeftPen().getLineWidth().floatValue() > FLOAT_ZERO) {
borderFlag |= Rectangle.LEFT;
lineWidth = box.getLeftPen().getLineWidth().floatValue();
lineColor = box.getLeftPen().getLineColor();
}
if (box.getTopPen().getLineWidth().floatValue() > FLOAT_ZERO) {
borderFlag |= Rectangle.TOP;
if (lineWidth == 0) {
lineWidth = box.getTopPen().getLineWidth().floatValue();
lineColor = box.getTopPen().getLineColor();
}
}
if (box.getRightPen().getLineWidth().floatValue() > FLOAT_ZERO) {
borderFlag |= Rectangle.RIGHT;
if (lineWidth == 0) {
lineWidth = box.getRightPen().getLineWidth().floatValue();
lineColor = box.getRightPen().getLineColor();
}
}
if (box.getBottomPen().getLineWidth().floatValue() > FLOAT_ZERO) {
borderFlag |= Rectangle.BOTTOM;
if (lineWidth == 0) {
lineWidth = box.getBottomPen().getLineWidth().floatValue();
lineColor = box.getBottomPen().getLineColor();
}
}
r.setBorder(borderFlag);
r.setBorderColor(lineColor);
r.setBorderWidth(lineWidth);
pdfContentByte.rectangle(r);
pdfContentByte.stroke();
pdfContentByte.setLineDash(FLOAT_ZERO);
pdfContentByte.setLineCap(PdfContentByte.LINE_CAP_ROUND);
}
private boolean isBoxVisible(JRLineBox box) {
return box.getLeftPen().getLineWidth().floatValue() > FLOAT_ZERO
|| box.getTopPen().getLineWidth().floatValue() > FLOAT_ZERO
|| box.getRightPen().getLineWidth().floatValue() > FLOAT_ZERO
|| box.getBottomPen().getLineWidth().floatValue() > FLOAT_ZERO
;
}
}