Home › Blog › How to Generate PDF in ASP.NET Core on Azure using DinkToPDF and wkhtmltopdfHow to Generate PDF in ASP.NET Core on Azure using DinkToPDF and wkhtmltopdf Chintan Prajapati April 2, 2026 18 min read Generating PDFs in ASP.NET Core is simple, when the application runs locally, but the same setup can fail after deployment to Azure App Service.The most common reasons are missing native dependencies, App Service plan limitations, OS-level differences, timeout errors, and font rendering issues.This guide explains how different open-source PDF libraries behave with ASP.NET Core and Azure, including wkhtmltopdf, DinkToPDF, and Rotativa.There are many ways to generate pdf using .net core using paid and free both types of components.But a problem comes into picture for a typical developer’s life on the day of release i.e deployment. He.I know you have been on such an adventure when all code works perfectly in your Windows PC and it doesn’t work in Staging or Live server. This used to happen to me too!!Then you realize that the open source component which you used is not compatible or has other dependencies which needs to be made available on the server.And then you do not control or manage the hosting for clients. Now you are in a trap. !!You may decide to rewrite code with another library, or suggest an option to buy a paid component for pdf generation.Which means time wasted, production deadlines crossed, and additional component cost to client. :( huh ..Too bad!!This happened to me again when my old open source pdf library was working nice on windows pc and windows server, and all of sudden i assumed that in azure also it would work without any problem.But I was wrong !!There were many limitations or details which I needed to be aware of before making my decision on choosing the right PDF generation library for azure and .net core.So to save your precious time, I have written a detailed article.Quick Answer: Best Way to Generate a PDF in ASP.NET Core on AzureIf you want to generate PDFs in an ASP.NET Core application hosted on Azure App Service, you can use open-source libraries like wkhtmltopdf, DinkToPDF, or Rotativa.However, the right choice depends on your Azure App Service operating system, pricing plan, and PDF formatting requirements.For simple HTML-to-PDF generation, wkhtmltopdf on Azure App Service Linux is usually the most practical option, especially when you want to avoid paid Windows hosting plans.For more control over margins, headers, footers, and page numbering, DinkToPDF can be a better choice, but it may require a paid Azure App Service plan depending on the deployment environment.If PDF generation is part of a larger cloud-hosted product, the Azure hosting plan, operating system, and deployment architecture should be decided early.For business applications that need scalable hosting, background processing, storage, and Microsoft technology support, Azure cloud-native application development can help you avoid common deployment issues.This guide compares these libraries, explains common Azure hosting issues, and shows how to generate PDFs with ASP.NET Core using code examples.Common Questions Before Generating PDFs in ASP.NET Core on AzureBefore choosing a PDF generation library for ASP.NET Core and Azure, these are the main questions developers usually have: Which open-source library works best for PDF generation in ASP.NET Core, C#, and Azure App Service? Does the Azure App Service operating system (Linux or Windows) affect PDF generation? Which Azure App Service plan is required for wkhtmltopdf, DinkToPDF, or Rotativa? Can PDF generation work on the Azure App Service Free Plan? What is the cost difference between Linux and Windows hosting for PDF generation?For teams building Microsoft-based applications, PDF generation is often one small part of a larger ASP.NET Core product.If your team needs support with web application development, backend services, or cloud deployment, working with an ASP.NET MVC development company can help you plan the architecture properly.If your answer is yes then i want to take your attention for the next 5 minutes.When I was searching in google for “generate pdf using .net core and azure ”. To achieve this I was searching to find the best open source library to work with.I found many libraries but here I am listing some of them in which I worked.For this comparison, we tested three common open-source PDF generation options for ASP.NET Core: wkhtmltopdf DinkToPDF RotativaEach library can generate PDFs, but their behavior changes depending on whether the application is hosted locally, on Azure Windows App Service, or on Azure Linux App Service.https://www.githubcompare.com/wkhtmltopdf/wkhtmltopdf+rdvojmoc/dinktopdf+webgio/rotativa.aspnetcore DinkToPDF vs wkhtmltopdf vs Rotativa for ASP.NET Core PDF GenerationLibraryBest ForAzure App Service NoteswkhtmltopdfBasic HTML-to-PDF generation in ASP.NET CoreWorks better with Azure Linux App Service when configured properlyDinkToPDFPDF customization, margins, headers, footers, and page numberingCan face timeout or dependency issues on Azure free plansRotativaGenerating PDFs from MVC viewsEasy to use locally, but may require a paid Azure App Service planPaid PDF librariesEnterprise use cases, support, and fewer hosting issuesGood option when open-source dependencies create deployment riskIf your requirement is only to convert basic HTML into PDF, wkhtmltopdf is a good starting point.If your PDF needs page numbers, custom headers, footers, margins, and layout control, DinkToPDF provides better configuration options.If your application is already MVC-based and you want to generate PDFs from views, Rotativa can be easier to implement.wkhtmltopdf PDF Generation in ASP.NET Corewkhtmltopdf is an open-source tool that converts HTML pages into PDF documents. In ASP.NET Core, it can be used through a NuGet package such as Wkhtmltopdf.NetCore.It is a good option for simple HTML-to-PDF conversion, but Azure deployment requires extra care because the library depends on native executable files. It is an open source library which is able to put several objects into the output file, an object is either a single webpage, a cover webpage or a table of contents. This library will work but with some conditions and limitations. Further I will describe this. Let’s see how we can use this. Create .Net Core empty web application. Install Wkhtmltopdf.NetCore NuGet Package. PM > Install-Package Wkhtmltopdf.NetCore -Version 3.0.2 Add One Controller. Here I have added a HomeController. And add this code in that controller.In real projects, PDF generation is often used for invoices, order documents, reports, purchase orders, or accounting exports.When those PDFs depend on data from CRMs, ERPs, accounting tools, or third-party systems, the PDF module should be planned along with the application’s custom API integration services. public class HomeController : Controller { private readonly IGeneratePdf _generatePdf; private static ILogger _logger; private readonly IFileProvider _fileProvider; public HomeController(IGeneratePdf generatePdf, ILogger<HomeController> logger, IFileProvider fileProvider) { _generatePdf = generatePdf; _logger = logger; _fileProvider = fileProvider; }[Obsolete] public IActionResult Index() { try { var bytes = _generatePdf.GetPDF(“<h1 style=’color:red’>Hello World<h1>”); System.IO.File.WriteAllBytes(Environment.ContentRootPath + @”PDfswkhtmltopdf.pdf”, bytes); return PhysicalFile(Environment.ContentRootPath + @”PDfswkhtmltopdf.pdf”, “application/pdf”); } catch (Exception ex) { _logger.LogInformation(“Error : ” + ex); var msg = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) msg = ex.InnerException.Message; System.IO.File.WriteAllText(Environment.ContentRootPath + @”PDfswkhtmltopdfError.txt”, msg); return PhysicalFile(Environment.ContentRootPath + @”PDfswkhtmltopdfError.txt”, “application/txt”); } } } Here the Library is providing the Interface Service IGeneratePdf. This service has many methods. Here for the demo I am using GetPDF in which we can pass html strings. And in the above code snippet you can see I have added the html. “<h1 style=’color:red’>Hello World<h1>” Use above code, save and run the application it will open the pdf file in the browser. Now Our challenge is to make it work with Azure Cloud App service. Create an App service and Publish the code into it. Here i have published my project into free app service plan If you are new with the app service and publishing code here is the reference : https://docs.microsoft.com/en-au/azure/app-service/quickstart-dotnetcore?tabs=net60&pivots=development-environment-vs Now here comes the limitation. And this limitation only comes into picture if Host is Azure. Here it is!wkhtmltopdf Issue on Azure App Service Free Plan Once your code has been published and run it will not work as it should. Rotativa folder with the wkhtmltopdf exe file as per system OS. you can get it from GitHub. Here is the link and paste this folder to the root folder with the help of Kudu Console https://github.com/fpanaccia/Wkhtmltopdf.NetCore/tree/master/Wkhtmltopdf.NetCore/Rotativa Once you run the application and it runs successfully then you will find the pdf with the incorrect fonts. But no worries. We have a solution and yes that’s why this article is all about.Solution The ultimate solution is to use it with Azure so that you need to upgrade the plan. Here I have used the Azure free plan, which has limited memory allocation and that’s why some features are not working So The plan I used is a free plan. You can check your plan by going to your app service and clicking on “Scale Up (App Service Plan) ” As shown in the above image the current plan is from Dev/Test and the pricing tier used is F1 free plan. So it won’t work in Any plans from Dev/Test section it will only work in the Any plans in Production section. Let’s try that…!wkhtmltopdf Result After Upgrading Azure App Service Plan Change the plan from free to paid in the Production section. You can select any plan from production. Here I am using the minimum plan. Once you applied, just restart the web app. And now run the web appAnd it works…! But now the big concern is price!! Why would you pay so much high ~5000 INR for an open-source PDF facility Rather I would buy a paid component. ! Anyways, I have figured out how to do this absolutely free in azure. Which i will share with you, i.e. how to leverage linux based free app service plan for PDF generation. And in which library it works seamlessly. Anyways, as of now lets move toward a second open source .net core library for pdf generation in azure.2. DinkToPDF PDF Generation in ASP.NET CoreDinkToPDF is a .NET wrapper around wkhtmltopdf. It is useful when you need more control over PDF settings such as paper size, orientation, margins, headers, footers, and page numbers. The source code for this library is in the GitHub CorePdfDemo repository. This is another open source library which is using the wkhtmltopdf wrapper. This library gives you more customization for generating PDFs in a convenient way. var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 18, Bottom = 18 }, }; It will give you options and methods to set the PDF size, margins, etc… I have created one example and here is the main code to use. private byte[] GeneratePdf(string htmlContent) { try { _logger.LogInformation("GeneratePdf started."); // Configure global settings for the PDF document var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 18, Bottom = 18 }, }; // Configure object settings for the HTML content var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = htmlContent, WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings = { FontSize = 10, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontSize = 8, Center = "PDF demo", Line = true } }; // Create the PDF document var htmlToPdfDocument = new HtmlToPdfDocument { GlobalSettings = globalSettings, Objects = { objectSettings }, }; // Convert HTML to PDF return _converter.Convert(htmlToPdfDocument); } catch (Exception ex) { _logger.LogError("Error in GeneratePdf: {Message}", ex.Message); return null; } } So once you download the code and run it it will work locally. Basically, the key thing which is required is DinkToPdf NugetPackage and the folder of v12.0.4. It is the wkhtmltopdf Wrapper. I have used the Invoice template for a demo. And you can find it in the Views folder. Here I used to save the pdf file to Azure Blob Storage after pdf generation. For that please provide your storage key and the pdf file name in the appsettings.json. Once all set the code Host the code into Azure app service. And run. And run this url to get your output : https://{AppServiceName}.azurewebsites.net/documentgenerator DinkToPDF Timeout Error on Azure App Service: After publishing the application to Azure App Service and opening the document generator URL, the request may take longer than expected and return a timeout error. Fix for DinkToPDF Timeout Error: In our test, the issue was fixed by moving the application to a paid Azure App Service Production plan, restarting the app, and running the PDF generation process again. Here, I am using the minimum plan for this. Apply the plan, Restart the app and run, you will get the desired output.Text screenshot from an Asp.Net Core application on Azure displaying: “{‘statusCode’: 200, ‘message’: ‘pdf file has been successfully uploaded’}. And when i see in the blob storage.Screenshot displaying a file directory with two PDF files: “GeneratedPdf.pdf” and “RazorTemplatePdf.pdf,” both labeled under the “Hot (inferred)” access tier. These files were efficiently managed using Asp.Net Core within the Azure ecosystem. So it’s all about choosing the right hosting plan and your code works well.DinkToPDF FooterSettings Example: Add Page [page] of [toPage]DinkToPDF allows you to add page numbers, headers, footers, margins, and layout settings using ObjectSettings. To show the current page number and total page count, you need to enable PagesCount and use placeholders like [page] and [toPage]. var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = htmlContent, WebSettings = { DefaultEncoding = "utf-8" }, HeaderSettings = { FontSize = 10, Right = "Page [page] of [toPage]", Line = true }, FooterSettings = { FontSize = 8, Center = "PDF demo", Line = true } }; SettingPurposePagesCount = trueEnables total page count calculation[page]Shows the current page number[toPage]Shows the total page countHeaderSettings.RightPlaces page numbers on the right side of the headerFooterSettings.CenterAdds centered footer textLine = trueAdds a separator line above/below the header or footerIf page numbers are not appearing correctly, check whether PagesCount is enabled and confirm that the required wkhtmltopdf native files are available in your deployment environment.3. Rotativa PDF Generation in ASP.NET CoreRotativa is another PDF generation library for ASP.NET Core. It is commonly used to generate PDFs from MVC views. In local development, it is easy to use, but Azure deployment still requires the wkhtmltopdf executable dependency.To use Rotativa, you need to add the required wkhtmltopdf executable inside the appropriate project folder and install Rotativa.AspNetCore NuGet package. It is the most easy to use library. After hosting it to Azure it won’t work with free plan it will only work with the Production Plan The result will be With the free plan it is showing timeout errorCommon Azure App Service Issues with PDF GenerationWhen PDF generation works locally but fails after Azure deployment, the issue is usually related to hosting limitations or missing dependencies. Common problems include:IssuePossible ReasonFixPDF works locally but not on AzureMissing native wkhtmltopdf filesAdd the correct executable/native library files during deployment500 timeout errorApp Service plan has limited memory or execution timeUpgrade the plan or use Linux App Service with a supported setupIncorrect fonts in PDFFonts are not available on the serverInstall required fonts or use web-safe fontsDinkToPDF page count not workingPagesCount is not enabledSet PagesCount = trueRotativa not working on free planDependency or execution restrictionUse a paid plan or test wkhtmltopdf on Linux App ServiceThis section will help the blog match more problem-solving queries and improve engagement.Why PDF Generation Fails on Azure Free Plan From the tests above, wkhtmltopdf, DinkToPDF, and Rotativa can work with ASP.NET Core and Azure, but some setups require paid Azure App Service plans because of memory limits, execution restrictions, and native dependency requirements.Generate PDF on Azure App Service Free Plan using Linux The most cost-effective solution we found was to host the ASP.NET Core application on Azure App Service with a Linux operating system. In this setup, wkhtmltopdf worked successfully on the Azure App Service free plan. The main change was the operating system. The application code remained mostly the same, but the hosting environment changed from Windows App Service to Linux App Service. I got success with only wkhtmltopdf library and the more additional and important benefit is that it worked on App service free plan. Create one Azure app service with Linux operating system with the free plan. Other configurations will be same except Operating system Here i am using the same code of wkhtmltopdf demo in windows with little bit changes. Use this code and publish it to the Azure App Service (Linux) with the free plan and it will work as expected. For the whole example code (https://github.com/satva-git/satvaPdf/tree/main/WkHtmlToPDF). public class HomeController : Controller { private readonly IGeneratePdf _generatePdf; private readonly ILogger<HomeController> _logger; private readonly IFileProvider _fileProvider; private readonly IConfiguration _config; // Ensure you have a configuration instance injected public HomeController(IGeneratePdf generatePdf, ILogger<HomeController> logger, IFileProvider fileProvider, IConfiguration config) { _generatePdf = generatePdf; _logger = logger; _fileProvider = fileProvider; _config = config; // Initialize the configuration instance } [Obsolete] public async Task<IActionResult> Index() { try { // Generate PDF var bytes = _generatePdf.GetPDF("<h1 style='color:red'>Hello World</h1>"); // Retrieve storage configuration values var connString = _config.GetValue<string>("StorageKey") ?? string.Empty; var blobContainer = _config.GetValue<string>("blobContainer") ?? string.Empty; var blobName = _config.GetValue<string>("blobName") ?? string.Empty; // Create the blob client var storageAccount = CloudStorageAccount.Parse(connString); var blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to the container and blob var container = blobClient.GetContainerReference(blobContainer); var blockBlob = container.GetBlockBlobReference(blobName); // Upload the byte array to the blob asynchronously await blockBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length); return Ok(new { Message = "File has been uploaded successfully." }); } catch (Exception ex) { // Log the error _logger.LogError("Error: {Message}", ex); // Create a message for the response var msg = ex.InnerException?.Message ?? ex.Message; return Ok(new { Message = "Error: " + msg }); } } } If you want to know more about the comparison of App service plans of windows and linux see the below table for your reference.For developers who are still evaluating the framework itself, ASP.NET Core is commonly used for cloud-based applications, APIs, web apps, and backend services. You can also read more about the advantages of ASP.NET Core before finalizing your technology stack.Azure Linux vs Windows App Service for PDF GenerationFor ASP.NET Core PDF generation, Azure Linux App Service can be a better option when you want to reduce hosting cost and use open-source PDF libraries. In this article’s test, wkhtmltopdf worked with Azure Linux App Service on the free plan, while DinkToPDF and Rotativa needed a paid production plan in the tested setup.Use Azure Linux App Service when: You want to test PDF generation with a lower hosting cost Your library supports Linux deployment You are comfortable managing native dependencies Your PDF generation requirement is basic to moderateUse Azure Windows App Service when: Your application or library depends on Windows-specific executables You are using Rotativa or DinkToPDF in a setup that requires Windows hosting You are okay with using a paid production plan You need fewer compatibility experiments during deploymentAzure App Service Linux vs Windows Pricing for PDF GenerationThe table below compares Azure App Service Linux and Windows pricing from the time of testing.Azure pricing may change based on region, currency, plan type, and Microsoft updates, so always verify the latest price in the Azure pricing calculator before making a final decision.Dev/TestPlanLinuxWindowsF1 Shared Infrastructure (Windows Only) 1 GB memory 60 min/day compute FreeFreeD1 Shared Infrastructure (Windows Only) 1 GB memory 240 min/day computeNot Applicable$9.49 /Month (Estimated)B1 100 Total ACU 1.75 GB memory A-Series compute equivalent$13.14 /Month(Estimated)$54.75 /Month(Estimated)B2 200 Total ACU 3.5 GB memory A-Series compute equivalent$26.28 /Month(Estimated)$109.50 /Month(Estimated)B3 400 Total ACU 7 GB memory A-Series compute equivalent$51.83 Month(Estimated)$219.00 /Month(Estimated)ProductionPlanLinuxWindowsP1V2 210 Total ACU 3.5 GB memory Dv2-Series compute equivalent $83.95 /Month (Estimated)$146.00 /Month (Estimated)P2V2 420 Total ACU 7 GB memory Dv2-Series compute equivalent$168.63 /Month(Estimated)$292.00 /Month(Estimated)P3V2 840 Total ACU 14 GB memory Dv2-Series compute equivalent$337.26 /Month(Estimated)$584.00 /Month(Estimated)P1V3 195 minimum ACU/vCPU 8 GB memory 2 vCPU $127.75/Month(Estimated)$244.55 /Month(Estimated)P2V3 195 minimum ACU/vCPU 16 GB memory 4 vCPU $255.50 /Month(Estimated)$489.10 /Month(Estimated)P3V3 195 minimum ACU/vCPU 32 GB memory 8 vCPU $511.00 /Month(Estimated)$978.20 /Month(Estimated)S1 100 Total ACU 1.75 GB memory A-Series compute equivalent $69.35 /Month (Estimated)$73.00 /Month (Estimated)S2 200 Total ACU 3.5 GB memory A-Series compute equivalent $138.70 /Month(Estimated)$146.00 /Month(Estimated)S3 400 Total ACU 7 GB memory A-Series compute equivalent $277.40 /Month(Estimated)$292.00 /Month(Estimated)Conclusion: Best PDF Generation Option for ASP.NET Core on Azure It is possible to generate pdf using dotnet core with Azure hosted apps with linux and windows operating system. If you want to use paid plans then use the windows operating system, whereas to use with free app service plan use wkhtmltopdf library with linux operating system in Azure hosted app service.Want to Build PDF using Azure and Asp. Core? Connect With us as we are the Best Azure Consulting Companies in Global. Frequently Asked QuestionsCan I generate PDFs in ASP.NET Core on Azure App Service?Yes, you can generate PDFs in ASP.NET Core on Azure App Service using libraries such as wkhtmltopdf, DinkToPDF, and Rotativa. However, the setup depends on the Azure App Service operating system, pricing plan, and the library native dependencies. Some PDF libraries work locally but may need extra configuration or a paid Azure App Service plan after deployment.Which library is best for generating PDFs in ASP.NET Core?For basic HTML-to-PDF conversion, wkhtmltopdf is a practical option. If you need more control over page size, margins, headers, footers, and page numbers, DinkToPDF can be a better choice. Rotativa is useful when you want to generate PDFs from MVC views, but it also depends on wkhtmltopdf and may require additional deployment setup.Does DinkToPDF work on Azure App Service?Yes, DinkToPDF can work on Azure App Service, but it may face timeout, dependency, or rendering issues depending on the App Service plan and hosting environment. In many cases, moving from a free plan to a paid production plan can help resolve execution and timeout issues.How do I add page numbers in DinkToPDF?You can add page numbers in DinkToPDF by enabling PagesCount = true and using placeholders such as [page] and [toPage] in HeaderSettings or FooterSettings. HeaderSettings = { FontSize = 10, Right = "Page [page] of [toPage]", Line = true } This displays the current page number and total page count in the PDF header.Why does wkhtmltopdf fail after deploying to Azure?wkhtmltopdf may fail on Azure because of missing native dependencies, restricted execution permissions, limited memory, timeout limits, or incorrect executable paths. It may work locally but fail after deployment if the Azure App Service environment does not include the required files or resources.Can I generate PDFs on the Azure App Service free plan?Yes, PDF generation can work on the Azure App Service free plan in some cases, especially when using wkhtmltopdf with Azure Linux App Service and the correct configuration. However, more complex setups with DinkToPDF or Rotativa may require a paid App Service plan because of resource and dependency limitations.Is Azure Linux or Windows App Service better for PDF generation?Azure Linux App Service can be a good option when you want lower hosting cost and your PDF library supports Linux deployment. Windows App Service may be needed when your application or PDF library depends on Windows-specific executable files. The better choice depends on the selected PDF library, deployment setup, and required PDF features.Why does PDF generation work locally but not on Azure?PDF generation often works locally because your development machine already has the required fonts, executables, memory, and permissions. On Azure App Service, the environment is different. Missing native files, limited free-plan resources, unavailable fonts, or OS-level dependency issues can cause the same code to fail after deployment.