Converting html to pdf from asp.net core controller generate empty pdf

When running the following code in a .net core console app it works fine and produces a pdf file correctly. Running the exact same code from an asp.net core mvc controller causes the pdf to be blank. no exeption is thrown, but document.Check() returns false. Is there a way to get a more detailed explanation as of why Check() fails?

var options = new HtmlLoadOptions
{
    IsRenderToSinglePage = true
};
var byteArray2 = Encoding.UTF8.GetBytes("<html><h1>hei</h1></html>");
var stream = new MemoryStream(byteArray2);
var pdfDocument= new Document(stream, options);
var res = pdfDocument.Check(false);
pdfDocument.Save(@"c:\temp\pdfs\hello.pdf");

I have the same problem when loading the html from file. No error messages, but empty document in hello2.pdf

var options = new HtmlLoadOptions();
var pdfDocument= new Document(@"c:\temp\pdfs\fil.html", options);
pdfDocument.Save(@"c:\temp\pdfs\hello2.pdf");

but generating a new pdf works fine, also from the controller:

Document document = new();
Page page = document.Pages.Add();
page.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello World!"));
document.Save(@"c:\temp\pdfs\hello3.pdf");

@snarum

Please ZIP and attach your input HTML along with your ASP.NET application here for testing. We will investigate the issue and provide you more information on it.

As you can see from my first example the html does not affect this. Sadly, I can’t send you my application. Creating a boiler plate mvc application did not provoke the error so I’ll investigate some more.

But it would be really helpful if the library would log the reason why Check() returns false somewhere.

I figured it out. There seems to be a strange bug in the library causing html->pdf conversion to generate an empty pdf if Thread.CurrentThread.CurrentCulture is set to “nb-NO”. The following code can run as a Console App

using System.Text;
using Aspose.Pdf;

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("nb-NO");
var htmlLoadOptions = new HtmlLoadOptions { IsRenderToSinglePage = true };
byte[] byteArray = Encoding.UTF8.GetBytes($"<html><h1>heisann</h1></html>");
using (var stream = new MemoryStream(byteArray))
{
    Document pdfDocument = new Document(stream, htmlLoadOptions);
    string pdfFile = Path.Combine("c:\\temp\\pdfs\\",
        $"home_{DateTime.Now.ToString("yyyy-MM-dd_HHmmss")}.pdf");

    pdfDocument.Save(pdfFile);
}

@snarum

We have logged this problem in our issue tracking system as PDFNET-53328. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.