Using Print View

To using Print View you have to go through next steps.

1. Install wkhtmltopdf v0.12.2.4

Note

While installing wkhtmltopdf better do not change the default installation directory, it allows to avoid needless configuration.

Note

If you install wkhtmltopdf on Linux without X Server, wkhtmltopdf should run via xvfb as below:

/usr/local/bin/wkhtmltopdf.sh
 #!/bin/bash
 xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf "$@"

Also do not forget to set the permission for execution:

chmod a+x /usr/local/bin/wkhtmltopdf.sh

2. Install InfinniPlatform.PrintView package:

dotnet add package InfinniPlatform.PrintView -s https://www.myget.org/F/infinniplatform/

3. Call AddPrintView() in ConfigureServices():

 using System;

 using InfinniPlatform.AspNetCore;

 using Microsoft.Extensions.DependencyInjection;

 public class Startup
 {
     public IServiceProvider ConfigureServices(IServiceCollection services)
     {
         services.AddPrintView();

         // ...

         return services.BuildProvider();
     }

     // ...
 }

4. Request the IPrintViewBuilder instance in the constructor:

 class MyComponent
 {
     private readonly IPrintViewBuilder _builder;

     public MyComponent(IPrintViewBuilder builder)
     {
         _builder = builder;
     }

     // ...
 }

5. Create the template using Print View Designer

6. Use the Build() method to generate the document:

Func<Stream> template;
object dataSource;
Stream outStream;

// ...

await _builder.Build(outStream, template, dataSource, PrintViewFileFormat.Pdf);