ITTEXT 7 - Doument Add方法在.Net Core中添加Paragraph对象时引发异常[重复]

mgdq6dx1  于 2023-06-25  发布在  .NET
关注(0)|答案(1)|浏览(120)
    • 此问题已在此处有答案**:

Null Reference Exception when calling iText7 PdfAcroForm.GetAcroForm() in .Net Core 3.1 class library(2个答案)
12天前关闭
我尝试使用ITEXT 7软件包生成一个简单的PDF。我只是从文档页面复制源代码,并尝试运行. Net Core控制台应用程序。它抛出一个异常。我不知道我错过了什么。我尝试了很多解决这个问题,但失败了。

    • 套餐信息:姓名: itext7 * 版本: 七月一日 *
    • 异常消息:**

Ex Message**"Object reference not set to an instance of an object." string**

class Program
{
    static void Main(string[] args)
    {
        PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileStream("G:/hello.pdf", FileMode.Create, FileAccess.Write)));
        Document document = new Document(pdfDocument, iText.Kernel.Geom.PageSize.A4);

        String line = "Hello! Welcome to iTextPdf";
        var para = new Paragraph(line);

        document.Add(new Paragraph(line));

        document.Close();
        Console.WriteLine("Awesome PDF just got created.");
        Console.WriteLine("Hello World!");
    }
}

nzk0hqpo

nzk0hqpo1#

有点晚了,但无论如何。
这是一个已知的iText问题,你可以在这个线程中找到解决方案:Null Reference Exception when calling iText7 PdfAcroForm.GetAcroForm() in .Net Core 3.1 class library

相关问题