# Getting Started with .NET PDF Library in Azure App Service Windows

The [.NET Core PDF library](https://www.syncfusion.com/document-sdk/net-pdf-library) is used to create, read, edit PDF documents programmatically without the dependency of Adobe Acrobat. Using this library, you can **create PDF document in Azure App Service on Windows**.

Check the following video to learn how to create a PDF document and publish it as an Azure App Service on Windows using the .NET PDF Library.
{% youtube "https://www.youtube.com/watch?v=PU8pVAHV_88" %}

## Prerequisites

* An active **Microsoft Azure subscription**.
* Visual Studio 2022 (17.0 or later) with the **ASP.NET and web development** and **Azure development** workloads installed.
* An active Syncfusion license. If you do not have one, request a free 30-day trial at [https://www.syncfusion.com/sales/communitylicense](https://www.syncfusion.com/sales/communitylicense).

## Steps to create PDF document in Azure App Service on Windows

Step 1: Create a new ASP.NET Core Web App (Model-View-Controller).
![Create a ASP.NET Core Web App project](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/create-net-core-web-app.png)

Step 2: Create a project name and select the location.
![Configure your new project](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/project_configuration.png)

Step 3: Click **Create** button.
![Additional information](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/framework_selection.png)

Step 4: Install the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).
![NuGet package installation](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/nuget_package.png)

Step 5: Register the Syncfusion<sup>&reg;</sup> license key. A trial watermark is added to every page of the generated PDF until a valid key is registered. Include the license key in **Program.cs** before initializing any Syncfusion<sup>&reg;</sup> component:

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Licensing;

var builder = WebApplication.CreateBuilder(args);
// Register the Syncfusion license
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

{% endhighlight %}
{% endtabs %}

Replace `"YOUR LICENSE KEY"` with the license key associated with your Syncfusion<sup>&reg;</sup> account. If you do not have a license key, you can request a free 30-day trial or apply for a Community License from the Syncfusion<sup>&reg;</sup> website. For more information about registering a license key in your application, refer to the [Syncfusion<sup>&reg;</sup> Licensing Documentation](https://help.syncfusion.com/common/essential-studio/licensing/overview).

Step 6: A default action method named Index will be present in *HomeController.cs*. Right click on Index method and select Go To View where you will be directed to its associated view page *Index.cshtml*. Add a new button in the *Index.cshtml* as shown below.

{% tabs %}

{% highlight CSHTML %}

@{
    Html.BeginForm("CreatePDFDocument", "Home", FormMethod.Get);
    {
        <div>
            <input type="submit" value="Create PDF Document" style="width:200px;height:27px" />
        </div>
    }
    Html.EndForm();
}

{% endhighlight %}

{% endtabs %}

Step 7: Include the following namespaces in *HomeController.cs*.

{% tabs %}

{% highlight c# tabtitle="C#" %}

using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;
using Syncfusion.Pdf.Grid;
using Syncfusion.Pdf;

{% endhighlight %}

{% endtabs %}

Step 8: Add a new action method named CreatePDFDocument in HomeController.cs file and include the below code example to generate a PDF document in *HomeController.cs*.

{% tabs %}

{% highlight c# tabtitle="C#" %}

//To load an existing file. 
private readonly IWebHostEnvironment _hostingEnvironment;
public HomeController(IWebHostEnvironment hostingEnvironment)
{
    _hostingEnvironment = hostingEnvironment;
}

public IActionResult CreatePDFDocument()
{
    //Create a new PDF document.
    PdfDocument document = new PdfDocument();
    //Set the page size.
    document.PageSettings.Size = PdfPageSize.A4;
    //Add a page to the document.
    PdfPage page = document.Pages.Add();

    //Create PDF graphics for the page.
    PdfGraphics graphics = page.Graphics;
    //Load the image from the disk.
    string imagePath = Path.Combine(_hostingEnvironment.WebRootPath, "Data/AdventureCycle.jpg");
    FileStream imageStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
    PdfBitmap image = new PdfBitmap(imageStream);
    //Draw an image.
    graphics.DrawImage(image, new RectangleF(130, 0, 250, 100));

    //Draw header text. 
    graphics.DrawString("Adventure Works Cycles", new PdfStandardFont(PdfFontFamily.TimesRoman, 20, PdfFontStyle.Bold), PdfBrushes.Gray, new PointF(150, 150));

    //Add paragraph. 
    string text = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";
    //Create a text element with the text and font.
    PdfTextElement textElement = new PdfTextElement(text, new PdfStandardFont(PdfFontFamily.TimesRoman, 12));
    //Draw the text in the first column.
    textElement.Draw(page, new RectangleF(0, 200, page.GetClientSize().Width, page.GetClientSize().Height));

    //Create a PdfGrid.
    PdfGrid pdfGrid = new PdfGrid();
    //Add values to the list.
    List<object> data = new List<object>();
    Object row1 = new { Product_ID = "1001", Product_Name = "Bicycle", Price = "10,000" };
    Object row2 = new { Product_ID = "1002", Product_Name = "Head Light", Price = "3,000" };
    Object row3 = new { Product_ID = "1003", Product_Name = "Break wire", Price = "1,500" };
    data.Add(row1);
    data.Add(row2);
    data.Add(row3);
    //Add list to IEnumerable.
    IEnumerable<object> dataTable = data;
    //Assign data source.
    pdfGrid.DataSource = dataTable;
    //Apply built-in table style.
    pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent3);
    //Draw the grid to the page of PDF document.
    pdfGrid.Draw(graphics, new RectangleF(0, 300, page.Size.Width - 80, 0));

    //Saving the PDF to the MemoryStream.
    MemoryStream stream = new MemoryStream();
    document.Save(stream);
    //Set the position as '0'.
    stream.Position = 0;
    //Download the PDF document in the browser.
    FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
    fileStreamResult.FileDownloadName = "Sample.pdf";
    return fileStreamResult;
}

{% endhighlight %}

{% endtabs %}

**Steps to publish as Azure App Service on Windows**

Step 1: Right-click the project and select **Publish** option.
![Publish option Image](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/publish_button.png)

Step 2: Click the **Add a Publish Profile** button.
![Add a publish profile](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/publish_profile.png)

Step 3: Select the publish target as **Azure**.
![Select the publish target as Azure](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/select_target.png)

Step 4: Select the Specific target as **Azure App Service (Windows)**.
![Select the publish target](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/select_azure-app-service-windows.png)

Step 5: To create a new app service, click **Create new** option.
![Click create new option](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/create_new_app_service.png)

Step 6: Click the **Create** button to proceed with **App Service** creation.
![Click the create button](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/app_service_details.png)

Step 7: Click the **Finish** button to finalize the **App Service** creation.
![Click the finish button](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/finish_app_service.png)

Step 8: Click **Close** button.
![Create a ASP.NET Core Project](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/profile_creation_success.png)

Step 9: Click the **Publish** button.
![Click the Publish button](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/publish_app_service.png)

Step 10: Now, Publish has been succeeded.
![Publish has been succeeded](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/publish_link.png)

Step 11: Now, the published webpage will open in the browser. 
![Browser will open after publish](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/webview.png)

Step 12: Select the PDF document and Click **Create PDF document** to create a PDF document. You will get the output PDF document as follows.
![Azure App Service on Windows](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-app-service-windows/output.png)

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Getting%20Started/Azure/Azure%20App%20Service).

Click [here](https://www.syncfusion.com/document-sdk/net-pdf-library) to explore the rich set of Syncfusion<sup>&reg;</sup> PDF library features.

An online sample link to [create PDF document](https://document.syncfusion.com/demos/pdf/default#/tailwind).

## Next steps

* [Create a PDF in Azure App Service on Linux](Create-PDF-document-in-Azure-App-Service-Linux.md)
* [Create a PDF in Azure Functions v4](Create-PDF-document-in-Azure-Functions-v4.md)
* [Create a PDF in an AKS cluster](Create-PDF-document-in-AKS-Environment.md)
* [Open and read an existing PDF document](Open-PDF-file.md)
* [Save the generated PDF to a file or stream](Save-PDF-file.md) 