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

1
  • 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? Commented Oct 1, 2021 at 20:15

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.