4

I need to convert some html to a PDF. I came across IText7 and it looks a good solution.

I am developing in .net core 3.1

But, even using a basic implementation of it I am getting an error:

string basicPage = "<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>"; using (FileStream pdfDest = File.Open(@"C:\Users\Trevo\Desktop\output.pdf", FileMode.OpenOrCreate)) { ConverterProperties converterProperties = new ConverterProperties(); HtmlConverter.ConvertToPdf(basicPage, pdfDest, converterProperties); } 

The error is everyone's favourite of:

Object reference not set to an instance of an object.

The inner exception is null and the only clue is the SerializationStackTraceString is:

at iText.IO.Font.FontCache..cctor()

So, it's pointing towards something to do with font?

The only suggestion I have found was to clean various directories and caches. I have created a clean solution from scratch and the same error occurs.

Can anyone offer any help please?

1
  • 1
    This isn't a resolution. More of a troubleshooting tip. iText may be looking to resolve an assembly that is not there. If you subscribe to the AppDomain.CurrentDomain.AssemblyResolve event, you can see if the AppDomain is trying to resolve (look for) an assembly that it cannot find. Here is the link: learn.microsoft.com/en-us/dotnet/api/… Commented Jan 14, 2021 at 14:49

2 Answers 2

3

Try using default font provider

 var converterProperties = new ConverterProperties(); converterProperties.SetFontProvider(new DefaultFontProvider(true, true, true)); 
Sign up to request clarification or add additional context in comments.

3 Comments

many thanks for the suggestion. added that line and now i get the error at this new line :(
Yes can you show the error or provide some more information
Same crash, same place at iText.IO.Font.FontCache..cctor(
3

Please see this:

Null Reference Exception when calling iText7 PdfAcroForm.GetAcroForm() in .Net Core 3.1 class library

And this:

iText7 convert HTML to PDF "System.NullReferenceException."

I would like to be able to flag any of them as duplicates, because they are all the same issue - internal issues with iText7's own code that we essentially have to ignore. However, I'm unable to flag them as duplicates because that functionality will only work if one of the answers is accepted.

But I just wanted you to know, it's not really your problem, it's theirs, so until they fix it, make sure you have "Just My Code" enabled in your settings.

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.