Articles in this section
Category / Section

How to create WinForms PDF document in Azure function?

7 mins read

The Syncfusion Essential® PDF is a feature-rich and high performance .NET PDF Library used to create, read, and edit PDF documents programmatically without Adobe dependencies. Using this library, you can create PDF document using .NET in Azure functions.

Steps to create PDF in Azure functions programmatically:

  1. Create a new Azure function project. Create azure functions project.
  2. Select framework Azure Functions v1 (.NET Framework) and HTTP trigger as follows. Select the framework and trigger.
  3. Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your Azure functions project from NuGet.org. Install Syncfusion.Pdf.WinForms nuget package.
  4. Include the following namespaces in Function1.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Graphics; 
using Syncfusion.Pdf.Grid;

 

  1. Add the following code snippet in Function1 class to create PDF document in Azure functions.

C#

//Create a new PDF document.
 PdfDocument document = new PdfDocument();
 //Add a page to the document.
 PdfPage page = document.Pages.Add();
 //Create PDF graphics for the page.
 PdfGraphics graphics = page.Graphics; 
//Set the standard font. 
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
 //Draw the text.
 graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
MemoryStream ms = new MemoryStream();
//Save the PDF document  
document.Save(ms);
ms.Position = 0;
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(ms.ToArray());
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
    FileName = "PDFDocument.pdf"
};
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
return response;

 

  1. Right-click the project and select Publish. Then, create a new profile in the Publish Window. Create new publish profile.
  2. Create App service using Azure subscription.Create a App service to publish.

 

  1. After creating the profile, click the publish button. Publish the functions to Azure.
  2. Now, go to Azure portal and select the Functions Apps. After running the service, click Get function URL > Copy. Paste the same in the new browser tab. You will get the output PDF document as follows. Output Screenshot.

A Complete working sample can be downloaded from PDFCreation_AzureFunction.zip

Take a moment to peruse the documentation, where you will find other options like drawing right-to-left text and multi-column text, consuming TrueType fonts, Standards fonts, and CJK fonts. Also, the features like PDF form filling, extract text or images from PDF, and protect PDF documents with code examples.

Refer here to explore the rich set of Syncfusion Essential® PDF features.

An online sample link to generate Hello world PDF document.

See Also:

Create a PDF file in Xamarin

Create a PDF file in ASP.NET Core

Create a PDF file in ASP.NET MVC

Create a PDF file in Windows Forms

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion® license key in your application to use the components without trail message.

 

Conclusion

I hope you enjoyed learning on how to create WinForms PDF document in Azure function.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!
Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied