iText - HtmlConverter.ConvertToPdf() - NullReferenceException

Viewed 529

I'm using iText to convert html to pdf as follows...

public static string HtmlToPdf(string DestinationFilename, string Html, HttpServerUtilityBase server)
    {
        string RelativePath = GetFilePath(server, DestinationFilename, overwrite: false);
        PdfDocument pdf = new(new PdfWriter(server.MapPath(RelativePath)));
        pdf.SetDefaultPageSize(PageSize.LETTER);
        HtmlConverter.ConvertToPdf(Html, pdf, new ConverterProperties().SetBaseUri("/Data/temp/"));
        return RelativePath;
    }

However, when HtmlConverter.ConvertToPdf() is executed, I am given a rather generic NullReferenceException - "Object reference not set to an instance of an object." exception.

It does actually convert the Html to pdf properly, but I would prefer not to put code into production that throws exceptions, but the exception details are not really helpful as far as i can read into them.

full exception:

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=itext.io
StackTrace:
at iText.IO.Font.FontCache..cctor()

As you can see it references FontCache, but I am not using FontCache here so I'm not sure what it's looking for.

Note: thought it could be a duplicate of this but adding using iText.IO.Font; has not had any effect.

tia.

0 Answers
Related