Skip to content

Commit

Permalink
Fix object reference error with encoding detector
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees committed Sep 1, 2024
1 parent 9e0bd73 commit ca53433
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ChromiumHtmlToPdfLib/Helpers/PreWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,16 @@ public string WrapFile(string inputFile, Encoding? encoding)
using var fileStream = File.OpenRead(inputFile);
_logger?.Info("Trying to detect encoding");
var result = CharsetDetector.DetectFromStream(fileStream);
encoding = result.Detected.Encoding;
_logger?.Info("{statusLog}", result.Detected.StatusLog);
if (result.Detected.Encoding != null)
{
encoding = result.Detected.Encoding;
_logger?.Info("{statusLog}", result.Detected.StatusLog);
}
else
{
encoding = Encoding.UTF8;
_logger?.Info("Could not detect encoding, falling back to UTF-8");
}
}

var streamReader = new StreamReader(inputFile, encoding);
Expand Down

0 comments on commit ca53433

Please sign in to comment.