1

I tried to generate a simple PDF using ITEXT 7 package. I just copy the source code from the documentation page and tried to run the .Net Core Console Application. It throws an exception. I'm not sure what I missed. I tried a lot to fix the issue but failed.

Package Info: Name: itext7 Version: 7.1.16

Exception Message:

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

ITEXT Documentation: https://itextpdf.com/en/products/itext-7/itext-7-core

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!");
    }
}

enter image description here

B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130
  • 1
    Hi, something's wrong with the dependencies/fonts, so definitely not a problem with code but rather something with the project set up. Can you attach your project file please? – Alexey Subach Oct 01 '21 at 20:15

1 Answers1

0

A little bit late, but anyhow.

This is a known iText problem, and you can find a solution in this thread: Null Reference Exception when calling iText7 PdfAcroForm.GetAcroForm() in .Net Core 3.1 class library

Matjaz
  • 1,301
  • 10
  • 7