In a recent project I used this solution to take fillable PDF forms, fill them out based on user input, flatten the PDF document and save it back to SharePoint. I can think of a number of uses for this type of solution: filling out contracts, filling out medical or other business forms, or just about any standard document that requires dynamic data inputted. This guide shows the fundamentals for accomplishing this, there are countless ways this could be modified to suit specific requirements.

Prerequisites

  1. A development environment with SharePoint 2010 and Visual Studio 2010 installed and configured
  2. A blank site on the SharePoint environment to work with
  3. A fillable PDF form (at least one), for this example I am using a sample Direct Deposit form from Microsoft Word that I converted to a PDF form. You can download the form here.
  4. iTextSharp (which can be downloaded here)

Guide

  1. Identify the names of the form fields that will be filled out by the application. (You can do this in Adobe Acrobat while editing the form). The field for our sample form are:

    • “Name of Financial Institution”
    • “Routing Number”
    • “Account Number”
    • “Checking”
    • “Savings”
  2. In your SharePoint site, create two Document Libraries named “Form Templates” and “Completed Forms”. (In a more complete solution, you might create content types and list definitions for these. For simplicity, we are just creating them on the site manually.)

  3. Upload your PDF form template (i.e. the Sample Form) to the “Form Templates” Document Library.

  4. Start Visual Studio 2010 and create a New Project. Select Visual Web Part for the template (Visual C# > SharePoint > 2010).

  5. Provide a Solution Name; for this guide we are using “PDFFormExample”. Select OK.

  6. Provide the local SharePoint site URL you will be testing with (on my machine I am using “http://localhost:8080/sites/pdfforms/”).

  7. Select Finish.

  8. In the Solution Explorer, right-click References > Add Reference. Browse to and add the iTextSharp DLL referece.

  9. In the “VisualWebPart1UserControl.ascx” user control, add the ASP.NET controls to gather the form information from the user. Here is my completed control:

  10. Open the “VisualWebPart1UserControl.ascx.cs” code behind file (you will need to expand VisualWebPart1 in the Solution Explorer).

  11. Add an event handler for the “Click” action on the button we added to the user control:

  12. Add Microsoft.SharePoint, System.IO, iTextSharp.text.pdf, and iTextSharp.text to the using list:

  13. Next, use the following code in the Page_Load function to query the form templates to populate the drop down list:

  14. Add the following code to the btnSubmit_Click function. Details on each step are in the code comments:

  15. Your completed code should look like:

  16. Right-click the project name (PDFFormExample) in the Solution Explorer > Deploy. This will deploy your new web part to the local SharePoint site you specificed when creating the project.

  17. Browse to your local SharePoint site. Add your new web part to a SharePoint page (will be under the Custom category).

  18. Submit some data. If all goes well, it should indicate the form was successfully submitted.

  19. You should now have a complete form in the Completed Forms library.

That’s it. You are now able to retrieve a PDF Form, fill it out programmatically, and save it back to SharePoint. Now it’s your turn to find good uses for this.


Pin It on Pinterest

Share This
%d bloggers like this: