Search code examples
c#asp.net-mvcwindowspdf-generationwkhtmltopdf

WKHTMLTOPDF configuration in a .NET 5 project


I am using a wkhtmltopdf plugin in my .NET 5 MVC project and can't seem to find where to input the configuration.

In the docu it reads that I need to put the params into a command line, however I do not have the program installed and simply just use it in my project via dependency injection.

Here is the Solution Explorer in VS: Project tree

I use the plugin this way: Services config in Startup.cs

Inserting the commands into the cmd line in VS does nothing. Aside from this, the plugin works like a charm!

Thank you for any hints. Cheers!


Solution

  • In .NET, you just need to do for example:

     ConvertOptions option = new();
     option.PageMargins.Bottom = 0;
     option.PageMargins.Top = 0;
     option.PageMargins.Left = 0;
     option.PageMargins.Right = 0;
     _generatePdf.SetConvertOptions(option);
    

    To set the options.