iText:如何添加一个控制高度的空行

问题描述 投票:0回答:2

我是iText的新手。我使用iText 5.5.3。

我研究并应用了我发现的添加空行的内容。例如

method 1:
document.add( Chunk.NEWLINE );

method 2:
document.add( new Phrase("\n") );

但是,我注意到空白行的高度太大了。我怎样才能减少它?

感谢致敬。

itext
2个回答
0
投票

我知道在90年代放弃使用表格进行页面布局,但我发现使用带有iTextSharp的表格通常可以提供很高的精确度。

document.Add(BlankLineDoc(16));

public static PdfPTable BlankLineDoc(int height)
{
    var table = new PdfPTable(1) {WidthPercentage = 100};
    table = BlankLineTable(table, height);
    return table;
}

public static PdfPTable BlankLineTable(PdfPTable table, int height, int border = Rectangle.NO_BORDER)
{
    var cell = new PdfPCell(new Phrase(" "))
    {
        Border = border,
        Colspan = table.NumberOfColumns,
        FixedHeight = height
    };
    table.AddCell(cell);
    return table;
}

使用表格时可以直接使用BlankLineTable


0
投票

你可以像这样设置空白行的高度:

 PdfPTable table2 = new PdfPTable(1);
    table2.getDefaultCell().setBorder(0);
    table2.getDefaultCell().setPadding(0);
    table2.setWidthPercentage(100);
    table2.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    addBlankLines(table2, 3 ,10);
document.add(table2);

public PdfPTable addBlankLines(PdfPTable table, int noOfLine , float height) {
    table.getDefaultCell().setFixedHeight(height);
    for (int i = 0; i < noOfLine; i++) {
        table.addCell(" ");
    }
    return table;
}
© www.soinside.com 2019 - 2024. All rights reserved.