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");
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);
}
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.