以下代码抛出“文档无页面”
using (var stream = new MemoryStream())
{
using (var document = new Document())
{
document.SetPageSize(PageSize.LETTER);
using (var pdfWriter = PdfWriter.GetInstance(document, stream))
{
document.Open();
PdfContentByte pdfContentByte = pdfWriter.DirectContent;
ColumnText columnText = new ColumnText(pdfContentByte);
columnText.SetSimpleColumn(0, 0, 100, 20);
columnText.AddElement(new Paragraph("Sample text", new Font(Font.FontFamily.HELVETICA, 20)));
columnText.Go();
document.Close();
}
}
byte[] pdfBytes = stream.ToArray();
// ...
}
如果不是这样做的话,我应该如何使用ColumnText
和DirectContent
?
我正在使用iTextSharp 5.5.3