环境:
iText 7.1.0
Java JDK-9.0.1
问题:
表的圆角点边框的线宽和线形属性将传递到同一页面上的单独行。其他边界类型没有表现出这种行为。
代码示例:
public class ITextTest
{
public static void main(String[] args)
{
try(PdfWriter writer = new PdfWriter("D:\\test.pdf"))
{
try(PdfDocument pdfDocument = new PdfDocument(writer))
{
pdfDocument.setDefaultPageSize(PageSize.A5);
pdfDocument.addEventHandler(PdfDocumentEvent.END_PAGE, new FooterEventHandler());
try(Document doc = new Document(pdfDocument))
{
for(int i=0;i < 38; i++)
doc.add(new Paragraph("test test test test test test test test test test test test test test test")
.addStyle(new Style().setTextAlignment(TextAlignment.JUSTIFIED)));
Table pdfTable = new Table(2);
pdfTable.setAutoLayout();
pdfTable.setHorizontalAlignment(HorizontalAlignment.CENTER);
pdfTable.setBorder(new RoundDotsBorder(new DeviceRgb(255, 0, 0), 3f, 1f));
pdfTable.addCell(new Cell().add(new Paragraph("hello")).setBorder(new RoundDotsBorder(new DeviceRgb(255, 0, 0), 3f, 1f)));
pdfTable.addCell(new Cell().add(new Paragraph("hello")).setBorder(new RoundDotsBorder(new DeviceRgb(255, 0, 0), 3f, 1f)));
pdfTable.addCell(new Cell().add(new Paragraph("hello")).setBorder(new RoundDotsBorder(new DeviceRgb(255, 0, 0), 3f, 1f)));
pdfTable.addCell(new Cell().add(new Paragraph("hello")).setBorder(new RoundDotsBorder(new DeviceRgb(255, 0, 0), 3f, 1f)));
doc.add(pdfTable);
for(int i=0;i < 18; i++)
doc.add(new Paragraph("test test test test test test test test test test test test test test test")
.addStyle(new Style().setTextAlignment(TextAlignment.JUSTIFIED)));
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
private static class FooterEventHandler implements IEventHandler
{
@Override
public void handleEvent(Event event)
{
PdfDocumentEvent docEvent = (PdfDocumentEvent)event;
PdfPage page = docEvent.getPage();
Rectangle pageSize = page.getPageSize();
PdfCanvas pdfCanvas = new PdfCanvas(page);
try(Canvas canvas = new Canvas(pdfCanvas, docEvent.getDocument(), pageSize))
{
canvas.setFontColor(DeviceRgb.BLACK);
float x = (pageSize.getLeft() + pageSize.getRight()) / 2;
float y = pageSize.getBottom() + 10;
canvas.showTextAligned("Page " + String.valueOf(docEvent.getDocument().getPageNumber(page)), x, y, TextAlignment.CENTER);
pdfCanvas.setStrokeColor(new DeviceRgb(java.awt.Color.BLACK));
pdfCanvas.moveTo(pageSize.getLeft() + 10, pageSize.getBottom() + 30);
pdfCanvas.lineTo(pageSize.getRight() - 10, pageSize.getBottom() + 30);
pdfCanvas.closePathStroke();
}
}
}
}