create new .Net Framework 8.1 / .Net 6 console application
install Nuget Packages:
itext7.pdfhtmlRazorLight
update csproj by adding the following:
<PropertyGroup>
<!-- This group contains project properties for RazorLight on .NET Core -->
<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
</PropertyGroup>
<PropertyGroup>
<LangVersion>10.0</LangVersion>
</PropertyGroup>reload project
build and run code
further reading: