Subscribe to our blog!


Export form entries to Pdf format

  • Form Entries
  • Export
  • IoC
  • Dependency Injection
  • PDF
By on

This blog post comes as a solution to the desired ability to export form entries to PDF format. See Sitefinity's feature request here.

Find the full code in GitHub repository here

Video demo

Click on the image below to watch a video demonstration:

Revision history settings for pages in Sitefinity

Solution plan

In order to create an export to PDF format, the iTextSharp third party library have been used. It provides an API for .NET to create and manipulate pdf documents.

In order to create new pdf exporter helper class, you must dig deeper into how the Excel export has been implemented. You will need to create a custom class that implement the DataItemExporterBase class. This will help you overriding only a few methods keeping the logic to configue the response to the base class. Currently Excel exporter uses the FormEntriesExportHttpHandler to put several query string paramaters as ExportingItemsTypeName and *StylesheetName. You can benefit from this logic without touching it. What you need to do in this case is to only create new dependency injection for a class that implelements the IDataItemExporter interface. That way benefitting from the IoC pattern, you can "theft" the logic that the current "Export as CSV" button is doing and force it to use your exporter.


1.Create dependency injection to register the pdf exporter:

You can either use the Global.asax Application_Start method or be smarter. Create a self-installing assembly via the PreApplicationStartMethodAttribute:

2.Implement the export logic

The export logic is done in a specific class called PdfExporter that is using the iTextSharp API. The code in the class is done in a similar fashion to the ExcelExporter class used for the default export to excel functionality. The important method that does the export is ExportToStream. Here's the code:

The code above uses the iTextSharp to create new pdf document and tables and fill the cells with form entry field values.


Back To List

By continuing to use this website you are agreeing to its use of cookies. To find out more, please see our cookie policy.