Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TallComponents in .NET Core

We have a number of ASP.NET Framework applications using TallComponents (TallPDF and PDFKit). Now we're transitioning some of that logic to .NET Core.

All of the examples I've seen only show how to use the web.config, but given that this has mostly been replaced by a completely new configuration mechanism in .NET Core (usually in the file appsettings.json), it's not all clear what will need to be done to implement this in .NET Core.

Does anyone have an example of using TallComponents licenses in ASP.NET Core?

like image 621
p.s.w.g Avatar asked Apr 07 '26 04:04

p.s.w.g


1 Answers

Since I was unable to find this answer anywhere else online, I'll document it here.

Start by adding a new section to the appsettings.json file:

{
  "TallComponentsLicenses": [
    {
      "key": "TallPDF.NET 5.0 Web Application Key",
      "value": "<YOUR LICENSE>"
    }
  ]
}

Create a simple model to describe this structure:

public class TallComponentsLicense
{
  public string Key { get; set; }
  public string Value { get; set; }
}

In Startup.cs, register each of the licenses with the global TallComponents.Licensing.LicenseCollection:

using TallComponents.Licensing;

...

public class Startup
{

  public Startup(IConfiguration configuration)
  {
    Configuration = configuration;
  }

  public IConfiguration Configuration { get; }
  
  ...
  
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
    
    ...
    
    var tallComponentsLicenses = Configuration.GetSection("TallComponentsLicenses");
    if (tallComponentsLicenses != null)
    {
      var licenses = tallComponentsLicenses.Get<TallComponentsLicense[]>();
      foreach (var license in licenses)
      {
        LicenseCollection.Add(license.Key, license.Value);
      }
    }
    
    ...
    
  }
  
}

Also, when using a Web Application Key, it depends upon there being specific assembly-level attributes. You can provide these manually (e.g. in an AssemblyInfo.cs file) or by specifying them in the csproj file, which is what I prefer:

<PropertyGroup>
  <Company>YOUR COMPANY NAME</Company>
  <Product>YOUR PRODUCT NAME</Product>
  <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
</PropertyGroup>
like image 64
p.s.w.g Avatar answered Apr 10 '26 01:04

p.s.w.g



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!