gpt4 book ai didi

c# - 使用 iTextSharp 创建的简单 PDF 无法用 Acrobat Reader 打开?

转载 作者:太空狗 更新时间:2023-10-29 23:18:56 24 4
gpt4 key购买 nike

我使用 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)时,我得到的只是以下消息:

There was an error opening this document. There was a problem reading this document (14).

问题出在哪里?我如何解决它?谢谢

最佳答案

重启VS后问题解决。没有进行任何代码更改。

关于c# - 使用 iTextSharp 创建的简单 PDF 无法用 Acrobat Reader 打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3476960/

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