/RazorHtmlToPdfExample

Example App to generate a PDF from a Razor template via HTML

Primary LanguageC#MIT LicenseMIT

create new .Net Framework 8.1 / .Net 6 console application

install Nuget Packages:

  • itext7.pdfhtml
  • RazorLight

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: