![]() create and populate a string builder with each of the // field names available in the subject PDFįoreach (DictionaryEntry de in ) PdfReader pdfReader = new PdfReader(pdfTemplate) ![]() create a new PDF reader based on the PDF template document title the form this.Text = " - " pdfTemplate String pdfTemplate = c:\Temp\PDF\fw4.pdf" / form fields identified can be used to map each of the / /// List all of the form fields into a textbox. The namespace and class declaration are in the default configuration. Note that the iTextSharp libraries have been included into the project. The file begins with the appropriate library imports needed to support the code. The following section will describe the contents of the code file. The template PDF itself is never populated and it is used only to define the format and contents of the completed PDF.įigure 2: Solution Explorer The Code: Main FormĪs was previously mentioned, all of the code used in the demonstration application is contained entirely in the project’s single Windows Form. The application uses the existing PDF as a template and from that template, it creates and populates the new PDF. The completed PDF is generated and stored in the local file system the PDF is not opened for display by the application. The form itself contains only a docked textbox used to display all of the field names from an existing PDF document. Note that a reference to the iTextSharp DLL has been included in the project.Īll of the project code is contained within the single Windows Form. However, any PDF with embedded controls (text boxes, check boxes, etc.) is fair game for this approach. I have also included a PDF that will be used for demonstration purposes this form is the IRS W-4 form completed by US taxpayers. The solution consists of a single Windows Forms project with a single form. In order to get started, fire up the Visual Studio 2005 IDE and open the attached solution. Further, although not demonstrated here, you can also use iTextSharp to create a PDF document with embedded controls. Of course, if you have access to Adobe tools (Adobe Professional, Adobe Designer), you can always create your own PDFs with controls or can add controls to existing PDFs. those meant to be printed and filled in with a pencil, cannot be completed using this approach. PDF documents that do not contain controls, i.e. The form contains controls and may be filled out programmatically so it serves as a good example. In order to demonstrate filling out a PDF using the iTextSharp DLL, I downloaded a copy of the W-4 PDF form from the IRS website. Use the link provided previously in order to download the DLL locally to your development machine. The examples contained herein are dependent upon the availability of the iTextSharp DLL. The download will contain examples of PDF creation in both Visual Basic and C#. The examples here are limited to a description of the procedures associated with the completion of a PDF. ![]() With the iTextSharp DLL, it is possible to not only populate fields in an existing PDF document, but also to dynamically create PDFs. The project is available for download through. ITextSharp is a C# port of a Java library written to support the creation and manipulation of PDF documents. The article also discusses how one might go about using the iTextSharp DLL to discover and map the fields available within an existing PDF if the programmer has only the PDF but, does not have Adobe Designer or even a list of the names of the fields present in the PDF.įigure 1: Resulting PDF after Filling in Fields Programmatically This article describes a quick and simple approach to programmatically completing a PDF document through the use of the iTextSharp DLL.
0 Comments
Leave a Reply. |