gpt4 book ai didi

java - iTextPDF:动态更改表格对齐方式

转载 作者:太空宇宙 更新时间:2023-11-04 07:04:51 26 4
gpt4 key购买 nike

我想动态对齐 iText PdfTable。

如何在 iTextPDF 中设置基于 x 和 y 位置的对齐方式。

PdfPCell cell;
cell = new PdfPCell(testTable);
cell.setFixedHeight(44f);
cell.setColspan(3);
cell.setBorder(0);
table.addCell(cell);
table1.addCell(table);

最佳答案

请查看这个示例...

public static void Main() {


// step 1: creation of a document-object
Document document = new Document();


try {


// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter writer = PdfWriter.getInstance(document, new FileStream("Chap1002.pdf", FileMode.Create));


// step 3: we open the document
document.Open();


// step 4: we grab the ContentByte and do some stuff with it
PdfContentByte cb = writer.DirectContent;


// we tell the ContentByte we're ready to draw text
cb.beginText();


// we draw some text on a certain position
cb.setTextMatrix(100, 400);
cb.showText("Text at position 100,400.");


// we tell the contentByte, we've finished drawing text
cb.endText();
}
catch(DocumentException de) {
Console.Error.WriteLine(de.Message);
}
catch(IOException ioe) {
Console.Error.WriteLine(ioe.Message);
}


// step 5: we close the document
document.Close();
}
}

关于java - iTextPDF:动态更改表格对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21575726/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com