- Notifications
You must be signed in to change notification settings - Fork0
License
solid-company/wrappers
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
SolidCompany.Wrappers.WkHtmlToImage
is a .NET Core wrapper for a part of an open-source projectwkhtmltopdf which iswkhtmltoimage
. It supports converting an HTML to images in a selected format.
You can getSolidCompany.Wrappers.WkHtmlToImage
package bydownloading it from NuGet feed.
SolidCompany.Wrappers.WkHtmlToImage
easily integrates with .NET Core Dependency Injection. You need only one line of code to get everything working:
publicvoidConfigureServices(IServiceCollectionservices){// ...services.AddHtmlToImageConversion();// ...}
Now you are free to use this powerful tool by injectingIHtmlToImage
into a constructor:
publicclassSampleService{privatereadonlyIHtmlToImagehtmlToImage;publicSampleService(IHtmlToImagehtmlToImage){this.htmlToImage=htmlToImage;}publicasyncTask<Stream>ConvertHtmlToImageAsync(stringhtml,intwidthPx){returnawaithtmlToImage.CreateImageAsync(html,widthPx,ImageFormat.Png);}}
Image height is automatically scaled to width which preserves a valid ratio.
You can pass a few additional options to configuration:
services.AddHtmlToImageConversion((serviceProvider,options)=>{options.DependencyLogger=newApplicationInsightsDependencyLogger(serviceProvider.GetRequiredService<TelemetryClient>());options.ExecutionTimeout=TimeSpan.FromMinutes(2);options.ExectuionDirectory=newCustomDirectory("C:/Temp");});
DependencyLogger
allows to track every wkhtmltoimage call withAzure Application Insights. To use it you needSolidCompany.Wrappers.Logging.ApplicationInsights
package.
ExecutionTimeout
lets you specify a maximumwkhtmltoimage
execution time. Default is 30 seconds.
ExectuionDirectory
specifies where the exe file is run and where temporary files are created. By default%TEMP%\SolidCompany.Wrappers.WkHtmlToImage
directory is used.