QuestPDF issue

Jonathan 230 Reputation points

Hi,

Can you help for the issues below? I did the change to add "Type" but still the same problem.

πŸ‘ User's image

0 comments No comments

Sign in to comment

Answer accepted by question author

Sumesh Ramasamy 0 Reputation points

Hello,

Welcome to the Microsoft Q&A and thank you for posting your question here.

I understand that you are still getting errors after adding Type for the QuestPDF license configuration in your .NET MAUI project.

From the screenshot, the main issue is that the code is placed directly inside the class body, but it needs to be inside the CreateMauiApp() method. Also, the QuestPDF license setting should be QuestPDF.Settings.License, not QuestPDF.Settings.LicenseType.

Please update your MauiProgram.cs like this:

using CommunityToolkit.Maui;
using QuestPDF.Infrastructure;

namespace Handle_PDF_MauiApp1;

public static class MauiProgram
{
 public static MauiApp CreateMauiApp()
 {
 QuestPDF.Settings.License = LicenseType.Community;

 var builder = MauiApp.CreateBuilder();

 builder
 .UseMauiApp<App>()
 .UseMauiCommunityToolkit();

 return builder.Build();
 }
}

Also, please make sure the .NET MAUI Community Toolkit NuGet package is installed in your project. Otherwise, UseMauiCommunityToolkit() will still show an error.

So the key changes are:

Put the code inside public static MauiApp CreateMauiApp()

Use QuestPDF.Settings.License = LicenseType.Community;

Make sure using QuestPDF.Infrastructure; is added

Make sure using CommunityToolkit.Maui; is added

Confirm that the CommunityToolkit.Maui NuGet package is installed

You can also refer to the official QuestPDF license configuration documentation here: https://www.questpdf.com/license/configuration.html

And the .NET MAUI Community Toolkit setup documentation here: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/get-started

I hope this is helpful. Please let me know if you have any other questions, steps or clarifications.

Please don’t forget to close the thread by upvoting and accepting it as an answer if it is helpful.

0 comments No comments

Sign in to comment

1 additional answer

  1. Nancy Vo (WICLOUD CORPORATION) 5,865 Reputation points β€’ Microsoft External Staff β€’ Moderator

    Hello @Jonathan ,

    Thanks for your question.

    I apologize for not being able to assist you previously. After conducting a more thorough investigation, I have identified the issue.

    Please put code inside a method, you can refer to my code example:

    MauiProgram.cs:

    using Microsoft.Extensions.Logging;
    using QuestPDF.Infrastructure;
    
    namespace TestPDF
    {
     public static class MauiProgram
     {
     public static MauiApp CreateMauiApp()
     {
     var builder = MauiApp.CreateBuilder();
     builder
     .UseMauiApp<App>()
     .ConfigureFonts(fonts =>
     {
     fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
     fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
     });
    
    #if DEBUG
     builder.Logging.AddDebug();
    #endif
     QuestPDF.Settings.License = LicenseType.Community;
     return builder.Build();
     }
     }
    }
    

    Please check whether, when using QuestPDF, the import statement is grayed out. I mean to confirm whether it is being used or not. If it is not used, I recommend checking the .csproj file and sharing it with me.

    I tested this on my end and it works.

    πŸ‘ User's image

    I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.

    1. Jonathan 230 Reputation points

      Thanks a lot. I had the issues below.

      πŸ‘ User's image

    2. Nancy Vo (WICLOUD CORPORATION) 5,865 Reputation points β€’ Microsoft External Staff β€’ Moderator

      Hi @Jonathan ,

      Since I did not use CommunityToolkit, my code was slightly different from yours. In case your code uses CommunityToolkit, you can refer to the new following code example:

      using Microsoft.Extensions.Logging;
      using QuestPDF.Infrastructure;
      using CommunityToolkit.Maui;
      
      namespace TestPDF
      {
       public static class MauiProgram
       {
       public static MauiApp CreateMauiApp()
       {
       var builder = MauiApp.CreateBuilder();
      
       builder
       .UseMauiApp<App>()
       .UseMauiCommunityToolkit()
       .ConfigureFonts(fonts =>
       {
       fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
       fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
       });
      
      #if DEBUG
       builder.Logging.AddDebug();
      
      
      #endif
       QuestPDF.Settings.License = LicenseType.Community;
       return builder.Build();
       }
       }
      }
      

      Furthermore, please follow these steps if you have not already done so:

      1. Please install missing packages if you have not already installed
      dotnet add package CommunityToolkit.Maui
      dotnet add package Microsoft.Extensions.Logging.Debug
      
      1. Clean & Rebuild the solution completely
      • Build β†’ Clean Solution
      • Build β†’ Rebuild Solution
      1. Check your .csproj file and make sure it contains:
      <ItemGroup>
       <PackageReference Include="CommunityToolkit.Maui" Version="..." />
       <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="..." />
       <PackageReference Include="QuestPDF" Version="..." />
      </ItemGroup>
      
      1. Make sure you have the proper using for CommunityToolkit at the top if you're calling .UseMauiCommunityToolkit().

    Sign in to comment
Sign in to answer

Your answer