我使用iTextSharp创建简单的测试PDF文档。我只是使用PdfContentByte来显示一些文本。以下是代码:
Document document = new Document();
Stream outStream = new FileStream("D:\\aaa\\test.pdf", FileMode.OpenOrCreate);
PdfWriter writer = PdfWriter.GetInstance(document, outStream);
document.Open();
PdfContentByte to = writer.DirectContent;
to.BeginText();
to.SetFontAndSize(BaseFont.CreateFont(), 12);
to.SetTextMatrix(0, 0);
to.ShowText("aaa");
to.EndText();
document.Close();
outStream.Close();
文件已创建,但当我尝试打开它(使用Acrobat Reader)时,只得到以下消息:
“打开文档时出现错误。读取文档时发生问题(14)。”
问题出在哪里?如何解决?谢谢。