So, at that moment, we discover that there is a library called iText. It’s a very complete and useful library and already exists several components using it, so we thought that would be rather easy to accomplish and develop this new component.
Well but, of course, there was a tiny issue in that scenario. The company didn’t want to pay for any license and didn’t want to add more costs to the project. So, we had to start looking if there was any library that could manipulate PDF files, and specifically, if it could fill a fillable PDF file.
After a few searches, we discovered the PDFsharp library.
“PDFsharp is an Open Source .NET library that easily creates and processes PDF documents on the fly from any .NET language. The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer.”
For more information click here.
Introducing PDFSharp — Fillable PDF
Using this component, you can automatically fill a fillable PDF form. At this moment, it only supports the following input types: Text (TXT), Combobox (CBX) and Checkbox (CHK). The basic use case scenario is:
- Insert the PDF file that you want to fill;
- Fetch all the fillable inputs in the pdf;
- Fill them with the correct information;
- Download the new PDF file filled.
The extension only has a structure and two server actions:
The structure Fields has three attributes that define each fillable input:
- Name, which matches the name of the input (set when a fillable pdf form is created);
- Type, which matches the type of input (TXT, CBX or CHK);
- Value, which matches the value already inserted (If the input is empty, it returns an empty value).
The action FormFields_Get receives as an input a Binary Data and, as an output, it returns all the fillable inputs in the Binary Data that you inserted.
The action FormFields_SetValues receives as an input a binary data and a list of Fields records. As an output, it returns the PDF file already filled with the correct information.
How to test and watch the functionalities
I created a simple test page. On that page, you will see a few instructions and reminders.
First, you can download the PDF file that I’m using as an example. It was a pdf that I created using Foxit, but you can create that file on any other program.
(Note: I strongly advise you to create a fillable PDF file using Foxit or Adobe, because I only tested this component with files created with these two programs. To create a fillable PDF file using these programs you have to pay, it’s not available on the free functionalities.)
Second, by clicking the button “Get Fields”, the list of all inputs available are shown in the list.
hird, you can set a value by each input, by clicking the button “Set Field” on each row, or you can insert the new information on each input and then click “Set Fields” to fill and download the new PDF file.
To define new values, the rules change for each type:
- Text Type — You can insert any value.
- Combo box — You can insert one of the options of the combo box, in this case, Portuguese, English or Deutsch, without the “(“ and “)”. It’s important that the text you insert has to match one of the options available in the combo box.
- Checkbox — You can insert “True” if you want to check that option, “False” if not.
Check here an example of the file filled already with the values that I inserted on that page:
And that’s it. This is still a work in progress and in the future can have more options and settings on the final PDF file. You can check and download the component by clicking here.