[英]iTextPDF: changing the Table Alignment dynamically
我想動態對齊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();
}
}
請查看我的書第4章示例的C#端口: http : //tinyurl.com/itextsharpIIA2C04
您可以將表添加到ColumnText
對象,並在絕對位置添加列:
ColumnText column = new ColumnText(writer.DirectContent);
column.AddElement(table);
column.SetSimpleColumn(llx, lly, urx, ury);
column.Go();
在此代碼段llx,lly和urx中,ury是頁面上列的左下角和右上角的坐標(請參見ColumnTable示例)。
在PdfCalendar示例中,使用了另一種方法:
table.WriteSelectedRows(0, -1, x, y, writer.DirectContent);
第一個參數定義需要繪制的行(0到-1表示所有行), x
和y
定義絕對位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.