# Getting Started with .NET PDF Library in Azure Functions v1

The [.NET 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 Functions v1**.

## Prerequisites

* An active **Microsoft Azure subscription**.
* Visual Studio 2019 or later with the **Azure development** workload installed.
* Azure Functions runtime **v1** with the **.NET Framework** worker.
* 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 a PDF document in Azure Functions v1

Step 1: Create a new Azure Functions project.
![Create a Azure Functions project](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/project_creation.png)

Step 2: Create a project name and select the location.
![Create a project name](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/configuration_project.png)

Step 3: Select function worker as **.NET Framework**.
![Select function worker](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/additional_information.png)

Step 4: Install the [Syncfusion.PDF.AspNet](https://www.nuget.org/packages/Syncfusion.Pdf.AspNet) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).
![Install Syncfusion.Pdf.AspNet NuGet package](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/nuget_package_reference.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 **Function1.cs** before initializing any Syncfusion<sup>&reg;</sup> component:

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Licensing;

[FunctionName("Function1")]
public static async Task<HttpResponseMessage> Run([HttpTrigger] HttpRequestMessage req, ...)
{
    // Register the Syncfusion license
    SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");

    // ... rest of the function body ...
}

{% 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).

N> Add the sample image *AdventureCycle.jpg* as an embedded resource in the project so it can be loaded using `Assembly.GetManifestResourceStream` in the code sample.

Step 6: Include the following namespaces in the **Function1.cs** file.

{% tabs %}
{% highlight c# tabtitle="C#" %}

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Grid;
using System.Drawing;

{% endhighlight %}
{% endtabs %}

Step 7: Add the following code example in **Run** method of **Function1** class to perform **create a PDF document** in Azure Functions and return the resultant **PDF document**.
{% tabs %}
{% highlight c# tabtitle="C#" %}

//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.
var assembly = Assembly.GetExecutingAssembly();
var imageStream = assembly.GetManifestResourceStream("Create-PDF-document.Data.AdventureCycle.jpg");
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));

//Save and close the PDF document  
MemoryStream ms = new MemoryStream();
document.Save(ms);
document.Close();
ms.Position = 0;

HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(ms.ToArray());
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
    FileName = "Sample.pdf"
};
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
return response;

{% endhighlight %}
{% endtabs %}

Step 8: Right-click the project and select **Publish**. Then, create a new profile in the Publish Window.
![Create a new profile in the Publish Window](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/publish_button.png)

Step 9: Select the target as **Azure** and click **Next** button.
![Select the target as Azure](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/set_azure_target.png)

Step 10: Select the **Create new** button.
![Configure Hosting Plan](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/function_insane.png)

Step 11: Click **Create** button.
![Select the plan type](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/hosting_sample.png)

Step 12: After creating app service then click **Finish** button.
![Creating app service](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/finish_function.png)

Step 13: Click the **Publish** button.
![Click Publish Button](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/click_publish_button.png)

Step 14: Publish has been succeeded.
![Publish succeeded](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v1/successful_publish.png)

Step 15: Now, go to Azure portal and select the App Services. After running the service, click **Get function URL > Copy**. Include the URL as a query string in the URL. Then, paste it into the new browser tab. You will get the PDF document as follows.
![Output document](https://help.syncfusion.com/document-processing/pdf/pdf-library/net/azure_images/azure-functions-v4/final_output.png)

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Getting%20Started/Azure/Azure%20Function%20V1).

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 a PDF document](https://document.syncfusion.com/demos/pdf/default#/tailwind).

## Next steps

* [Create a PDF in Azure Functions v4](Create-PDF-document-in-Azure-Functions-v4.md)
* [Create a PDF in Azure App Service on Windows](Create-PDF-document-in-Azure-App-Service-Windows.md)
* [Create a PDF in Azure App Service on Linux](Create-PDF-document-in-Azure-App-Service-Linux.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)