简体   繁体   中英

remove FixedLeading in first line of every page itext 7

PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST));
Document doc = new Document(pdfDoc);
doc.setMargins(0,0,0,0);
for (int i = 0; i <20 ; i++) {
    Paragraph element = new Paragraph("p " + i);
    if(i!=0) {
        element.setPadding(0);
        element.setMargin(0);
        element.setFixedLeading(255);
        doc.add(element);
    }
}

程序的输出

How do I remove the indent from the top of the first line?

You don't draw the first line (for i=0 ) at all, so for all lines you do draw you have explicitly set a leading.

To also draw the first line, move the doc.add out of the if body:

for (int i = 0; i <20 ; i++) {
    Paragraph element = new Paragraph("p " + i);
    if(i!=0) {
        element.setPadding(0);
        element.setMargin(0);
        element.setFixedLeading(255);
    }
    doc.add(element);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM