# Create or Generate PDF Files in ASP.NET Core with C#

> Text Control's digital document processing libraries can be used for the editing, creation, and viewing of Adobe PDF documents. In this tutorial, you will learn how to create a new ASP.NET Core Web application that generates PDF documents and how to make those documents available by using the Document Viewer.

- **Author:** Bjoern Meyer
- **Published:** 2023-10-02
- **Modified:** 2026-07-17
- **Description:** Text Control's digital document processing libraries can be used for the editing, creation, and viewing of Adobe PDF documents. In this tutorial, you will learn how to create a new ASP.NET Core Web application that generates PDF documents and how to make those documents available by using the Document Viewer.
- **4 min read** (779 words)
- **Tags:**
  - Adobe PDF
  - ASP.NET
  - ASP.NET Core
- **Web URL:** https://www.textcontrol.com/blog/2023/10/02/create-or-generate-pdf-files-in-aspnet-core-with-csharp/
- **LLMs URL:** https://www.textcontrol.com/blog/2023/10/02/create-or-generate-pdf-files-in-aspnet-core-with-csharp/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2023/10/02/create-or-generate-pdf-files-in-aspnet-core-with-csharp/llms-full.txt

---

Text Control's libraries for digital document processing can be used to edit, create, and view Adobe PDF documents. In this tutorial, you will learn how to create a new ASP.NET Core Web application that generates PDF documents and how to make those documents available by using the Document Viewer.

> **Requirements**
> 
> In order to create the project in this tutorial, it is required to install TX Text Control .NET Server. Download a trial version here:
> 
> [Download trial version](https://www.textcontrol.com/product/tx-text-control-dotnet-server/download/)

### Creating the Application

Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0).

1. In Visual Studio 2022, create a new project by choosing *Create a new project*.
2. Select *ASP.NET Core Web App (Model-View-Controller)* as the project template and confirm with *Next*.
3. Choose a name for your project and confirm with *Next*.
4. In the next dialog, choose *.NET 6 (Long-term support)* as the *Framework*, disable *Configure for HTTPS* for effortless testing, do not check *Enable Docker* and confirm with *Create*.
    
    ![Creating the .NET 6 project](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/02/b/assets/visualstudio1.webp "Creating the .NET 6 project")

#### Adding the NuGet Package

5. In the *Solution Explorer*, select your created project and choose *Manage NuGet Packages...* from the *Project* main menu.
    
    Select *Text Control Offline Packages* from the *Package source* drop-down.
    
    *Install* the latest version of the following packages:
    
    
    - *TXTextControl.TextControl.ASP.SDK*
    - *TXTextControl.Web.DocumentViewer*
    
    ![ASP.NET Core Web Application](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/02/b/assets/visualstudio2.webp "ASP.NET Core Web Application")

#### Building the Document

The TX Text Control API is used to generate a document that can be exported to all supported file formats, including PDF and PDF/A.

6. Find the *HomeController.cs* file in the *Controllers* folder. Replace the *Index()* method with the following code:
    
    ```
    public IActionResult Index()
    {
        using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
        {
            tx.Create();
    
            // adding static text
            TXTextControl.Selection sel = new TXTextControl.Selection();
            sel.Text = "Welcome to Text Control\r\n";
            sel.Bold = true;
    
            tx.Selection = sel;
    
            // adding merge fields
            TXTextControl.DocumentServer.Fields.MergeField mergeField =
              new TXTextControl.DocumentServer.Fields.MergeField()
              {
                  Text = "{{company}}",
                  Name = "company",
                  TextBefore = "Company name: "
              };
    
            tx.ApplicationFields.Add(mergeField.ApplicationField);
    
            // merge fields with MailMerge engine
            using (TXTextControl.DocumentServer.MailMerge mailMerge =
              new TXTextControl.DocumentServer.MailMerge())
            {
                mailMerge.TextComponent = tx;
                mailMerge.MergeJsonData("[{\"company\": \"Text Control, LLC\" }]");
            }
    
            byte[] baPdf;
            tx.Save(out baPdf, TXTextControl.BinaryStreamType.AdobePDF);
    
            ViewBag.Document = baPdf;
        }
    
        return View();
    }
    ```

> **Learn More**
> 
> In the example above, the document is created from scratch. However, there are many ways to create a PDF document, from using MS Word templates to converting other formats to PDF.
> 
> [Creating PDF Files using TX Text Control .NET in C# ](https://www.textcontrol.com/blog/2022/05/24/creating-pdf-files-using-tx-text-control-dotnet/llms-full.txt)

#### Displaying the PDF

In order to deploy the PDF document, the Document Viewer is used to render the document that has been generated.

7. Find the *Index.cshtml* file in the *Views -> Home* folder. Replace the complete content with the following code:
    
    ```
    @using TXTextControl.Web.MVC.DocumentViewer
    @using System.Text
    	        
    <div style="width: 800px; height: 600px;">
    	    
    @Html.TXTextControl().DocumentViewer(settings => {
    	settings.DocumentData = Convert.ToBase64String(ViewBag.Document);
    	settings.Dock = DocumentViewerSettings.DockStyle.Fill;
    }).Render()
    	    
    </div>
    ```

Compile and start the application.

![Rendered PDF](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/02/b/assets/results.webp "Rendered PDF")

#### Adding PDF.js Support

PDF documents are rendered using TX Text Control by default. You can add a reference to PDF.js to use this rendering engine for the display of PDF documents in the Document Viewer.

8. Right-click the project in the *Solution Explorer* and select *Add -> Client-Side Library...* from the context menu.
9. In the dialog that opens, type *pdf.js* in the *Library* text box and let Visual Studio autocomplete the entry with the latest version. Make sure that *Include all library files* is selected and confirm with *Install*.
    
    ![Rendered PDF](https://s1-www.textcontrol.com/assets/dist/blog/2023/10/02/b/assets/pdfjs.webp "Rendered PDF")
10. Find the *Index.cshtml* file in the *Views -> Home* folder. Replace the complete content with the following code:
    
    ```
    @using TXTextControl.Web.MVC.DocumentViewer
    @using System.Text
    	        
    <div style="width: 800px; height: 600px;">
    	    
    @Html.TXTextControl().DocumentViewer(settings => {
    	settings.DocumentData = Convert.ToBase64String(ViewBag.Document);
    	settings.Dock = DocumentViewerSettings.DockStyle.Fill;
    	settings.DocumentLoadSettings.PDFJS.BasePath = "lib/pdf.js/";
    }).Render()
    	    
    </div>
    ```
    
    > **Using CDN Package Sources**
    > 
    > In the example above, the PDF.js files are imported directly into the project. If you want to link to a CDN-hosted version, simply add the full path to the *BasePath* property.
    > 
    > ```
    > @using TXTextControl.Web.MVC.DocumentViewer
    > @using System.Text
    > 	        
    > <div style="width: 800px; height: 600px;">
    > 	    
    > @Html.TXTextControl().DocumentViewer(settings => {
    > 	settings.DocumentData = Convert.ToBase64String(ViewBag.Document);
    > 	settings.Dock = DocumentViewerSettings.DockStyle.Fill;
    > 	settings.DocumentLoadSettings.PDFJS.BasePath = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146";
    > }).Render()
    > 	    
    > </div>
    > ```

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Merging Barcodes with JSON Data in C#](https://www.textcontrol.com/blog/2022/02/14/merging-barcodes-with-json-data-in-csharp/llms.txt)
- [Create or Generate Adobe PDF files in ASP.NET Core with C#](https://www.textcontrol.com/blog/2022/02/11/create-or-generate-adobe-pdf-files-in-apsnet-core/llms.txt)
- [Silicon Valley, Here We Come!](https://www.textcontrol.com/blog/2026/08/10/silicon-valley-here-we-come/llms.txt)
- [Against the Trend: Why We Still Believe in Transparent, Perpetual Software Licensing. And Why You Should Too](https://www.textcontrol.com/blog/2026/08/06/against-the-trend-transparent-perpetual-software-licensing/llms.txt)
- [Unlock the Full Value of Your TX Text Control License](https://www.textcontrol.com/blog/2026/08/06/unlock-the-full-value-of-your-tx-text-control-license/llms.txt)
- [Introducing TX Text Control Web Collaboration Preview for ASP.NET Core](https://www.textcontrol.com/blog/2026/08/05/introducing-tx-text-control-web-collaboration-preview-for-asp-net-core-document-editors/llms.txt)
- [Building Long-Term Trust with Digital Signatures and Timestamps in C# .NET](https://www.textcontrol.com/blog/2026/08/04/building-long-term-trust-with-digital-signatures-and-timestamps-in-c-sharp-dot-net/llms.txt)
- [AI Natural Language Document Generation with MCP and TX Text Control .NET](https://www.textcontrol.com/blog/2026/07/16/ai-natural-language-document-generation-with-mcp-server-and-tx-text-control-dotnet/llms.txt)
- [WeAreDevelopers World Congress Europe 2026 Wrap Up: Record Breaking Days in Berlin](https://www.textcontrol.com/blog/2026/07/13/wearedevelopers-world-congress-europe-2026-wrap-up-record-breaking-days-in-berlin/llms.txt)
- [C# Document Generation: A Developer's Guide for .NET](https://www.textcontrol.com/blog/2026/07/08/csharp-document-generation-developer-guide-for-dotnet/llms.txt)
- [Validating PDF/UA Documents in .NET C#: A Practical Guide](https://www.textcontrol.com/blog/2026/07/06/validating-pdf-ua-documents-in-dotnet-csharp/llms.txt)
- [See Text Control at WeAreDevelopers World Congress Europe 2026 in Berlin](https://www.textcontrol.com/blog/2026/07/06/see-text-control-at-wearedevelopers-world-congress-europe-2026-in-berlin/llms.txt)
- [DWX 2026 Wrap-Up: Four Days of Innovation, Conversations, and Enterprise Document Solutions](https://www.textcontrol.com/blog/2026/07/03/dwx-2026-wrap-up-four-days-of-innovation-conversations-and-enterprise-document-solutions/llms.txt)
- [Create SignFabric Envelopes from Mail Merge Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/23/create-signfabric-envelopes-from-mail-merge-templates-using-dotnet-csharp/llms.txt)
- [Convert SSRS RDL Reports to DOCX and TX Text Control Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/22/convert-ssrs-rdl-reports-to-docx-and-tx-text-control-templates-in-dotnet-csharp/llms.txt)
- [Export Document Tables to CSV in .NET C#](https://www.textcontrol.com/blog/2026/06/19/export-document-tables-to-csv-in-dotnet-csharp/llms.txt)
- [Major SignFabric Updates: Stronger Audit Trails, Validation, and Recipient Workflows](https://www.textcontrol.com/blog/2026/06/17/major-signfabric-updates-stronger-audit-trails-validation-and-recipient-workflows/llms.txt)
- [Text Control Expands North American Conference Presence with WeAreDevelopers World Congress North America](https://www.textcontrol.com/blog/2026/06/12/text-control-expands-north-american-conference-presence-with-wearedevelopers-world-congress-north-america/llms.txt)
- [Converting HTML to Markdown in C# .NET](https://www.textcontrol.com/blog/2026/06/11/converting-html-to-markdown-in-csharp-dot-net/llms.txt)
- [Beyond WebSockets: A Glimpse into the Future of Document Editing with WebAssembly](https://www.textcontrol.com/blog/2026/06/10/beyond-websockets-glimpse-future-document-editing-webassembly/llms.txt)
- [Showcasing the Future of Document Processing at Developer World DWX 2026](https://www.textcontrol.com/blog/2026/06/08/showcasing-the-future-of-document-processing-at-dwx-developer-week-2026/llms.txt)
- [PDF Security Explained: Passwords, Permissions, Encryption and Digital Signatures in C# .NET](https://www.textcontrol.com/blog/2026/06/08/pdf-security-explained-passwords-permissions-encryption-and-digital-signatures-in-csharp-dotnet/llms.txt)
- [NDC Copenhagen 2026: Great Days in the Heart of Copenhagen's Developer Community](https://www.textcontrol.com/blog/2026/06/05/ndc-copenhagen-2026-great-days-in-the-heart-of-copenhagens-developer-community/llms.txt)
- [Automatically Mapping TX Text Control Form Fields to JSON Data in .NET C#](https://www.textcontrol.com/blog/2026/06/03/automatically-mapping-tx-text-control-form-fields-to-json-data-in-dotnet-csharp/llms.txt)
- [Getting Started with SignFabric: From Clone to Your First Signature Envelope](https://www.textcontrol.com/blog/2026/06/02/getting-started-with-signfabric-from-clone-to-your-first-signature-envelope/llms.txt)
