Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Chart
Search :       Advanced Search »
Home » Windows Forms C# » Fill in PDF Form Fields using the Open Source iTextSharp DLL

Fill in PDF Form Fields using the Open Source iTextSharp DLL

This article describes a quick and simple approach to programmatically completing a PDF document through the use of the iTextSharp DLL.

Author Rank :
Page Views : 118193
Downloads : 3689
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
PdfGenCSpackage.zip
 
 
Team Foundation Server Hosting
Become a Sponsor
Nevron Chart
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Introduction:

This article describes a quick and simple approach to programmatically completing a PDF document through the use of the iTextSharp DLL. 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.



Figure 1: Resulting PDF after Filling in Fields Programmatically.
 

iTextSharp is a C# port of a Java library written to support the creation and manipulation of PDF document; the project is available for download through SourceForge.net here:  http://sourceforge.net/projects/itextsharp/

With the iTextSharp DLL, it is possible to not only populate fields in an existing PDF document but also to dynamically create PDFs. The examples here are limited to a description of the procedures associated with completion of a PDF; the download will contain examples of PDF creation in both Visual Basic and C#.

The examples contained herein are dependent upon the availability of the iTextSharp DLL; use the link provided previously in order to download the DLL locally to your development machine.

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. The form contains controls and may be filled out programmatically so it serves as a good example. 

PDF documents that do not contain controls; those meant to be printed and filled in with a pencil, cannot be completed using this approach. Of course if you have access to the Adobe tools (Adobe Professional, Adobe Designer), you can always create your own PDFs with controls, or can add controls to existing PDFs. Further, though not demonstrated here, one can also use iTextSharp to create a PDF document with embedded controls. 

Getting Started:

In order to get started, fire up the Visual Studio 2005 IDE and open the attached solution. The solution consists of a single Win Forms project with a single form. 

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; however, any PDF with embedded controls (text boxes, check boxes, etc.) is fair game for this approach. Note that a reference to the iTextSharp DLL has been included in the project.

All of the project code is contained with the single Windows form. The form itself contains only a docked textbox used to display all of the field names from an existing PDF document. The completed PDF is generated and stored in the local file system; the PDF is not opened for display by the application. 

The application uses the existing PDF as a template and from that template; it creates and populates the new PDF. The template PDF itself is never populated and it is used only to define the format and contents of the completed PDF.



Figure 2: Solution Explorer
.

The Code:  Main Form

As was previously mentioned, all of the code used in the demonstration application is contained entirely in the project's single Windows form. The following section will describe the contents of the code file.

The file begins with the appropriate library imports needed to support the code.  Note that the iTextSharp libraries have been included into the project. The namespace and class declaration are in the default configuration. 

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using iTextSharp;

using iTextSharp.text;

using iTextSharp.text.pdf;

using iTextSharp.text.xml;

using System.IO; 

 

namespace PdfGenerator

{

    public partial class Form1 : Form

    {      

 

The next section of code contains the default constructor and the form 1 load event handler. During form load, two functions are called; those functions are used to display all of the fields present in the template PDF and to create a new PDF populated with a set of field values. 

 

public Form1()

{

    InitializeComponent();

} 

 

private void Form1_Load(object sender, EventArgs e)

{

    ListFieldNames();

    FillForm();

}

 

The next section of code contained in the demo application defines a function used to collect the names of all of the fields from the target PDF. The field names are displayed in a text box contained in the application's form. 

 

/// <summary>

/// List all of the form fields into a textbox.  The

/// form fields identified can be used to map each of the

/// fields in a PDF.

/// </summary>

private void ListFieldNames()

{

    string pdfTemplate = @"c:\Temp\PDF\fw4.pdf";

 

    // title the form

    this.Text += " - " + pdfTemplate;

 

    // create a new PDF reader based on the PDF template document

    PdfReader pdfReader = new PdfReader(pdfTemplate);

 

    // create and populate a string builder with each of the

    // field names available in the subject PDF

    StringBuilder sb = new StringBuilder();

    foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)

    {

        sb.Append(de.Key.ToString() + Environment.NewLine);

    }

 

    // Write the string builder's content to the form's textbox

    textBox1.Text = sb.ToString();

    textBox1.SelectionStart = 0;

} 

 

Figure 3 shows the field names collected from the target PDF using the ListFieldNames function call. In order to map these fields to specific fields in the PDF, one need only copy this list and pass values to each of the fields to identify them. For example, if the form contains ten fields, setting the value (shown next) to a sequential number will result in the display of the numbers 1 to 10 in each of the fields. One can then track that field value back to the field name using this list as the basis for the map. Once the fields have been identified, the application can be written to pass the correct values to the related field.

 

Checkbox controls may be a little more challenging to figure out. I tried passing several values to the checkbox controls before lining up a winner. In this example, I tried pass zero, one, true, false, etc. to the field before figuring out that 'yes' sets the check.


Figure 3: The Available PDF Fields.
 

The next section of code in the demo project is used to fill in the mapped field values. The process is simple enough, the first thing that happens is that that the template file and new file locations are defined and passed to string variables. Once the paths are defined, the code creates an instance of the PDF reader which is used to read the template file, and a PDF stamper which is used to fill in the form fields in the new file. Once the template and target files are set up, the last thing to do is to create an instance of the AcroFields which is populated with all of the fields contained in the target PDF. After the form fields have been captured, the rest of the code is used to fill in each field using the field's SetField function.

 

In this example, the first worksheet and the W-4 itself are populated with meaningful values whilst the second worksheet is populated with sequential numbers which are then used to map those fields to their location on the PDF.

 

After the PDF has been filled out, the application reads values from the PDF (the first and last names) in order to generate a message indicating that the W-4 for this person was completed and stored. 

 

private void FillForm()

{

    string pdfTemplate = @"c:\Temp\PDF\fw4.pdf";

    string newFile = @"c:\Temp\PDF\completed_fw4.pdf";

 

    PdfReader pdfReader = new PdfReader(pdfTemplate);

    PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));

    AcroFields pdfFormFields = pdfStamper.AcroFields;

 

    // set form pdfFormFields

    // The first worksheet and W-4 form

    pdfFormFields.SetField("f1_01(0)", "1");  

    pdfFormFields.SetField("f1_02(0)", "1");

    pdfFormFields.SetField("f1_03(0)", "1");

    pdfFormFields.SetField("f1_04(0)", "8");

    pdfFormFields.SetField("f1_05(0)", "0");

    pdfFormFields.SetField("f1_06(0)", "1");

    pdfFormFields.SetField("f1_07(0)", "16");

    pdfFormFields.SetField("f1_08(0)", "28");

    pdfFormFields.SetField("f1_09(0)", "Franklin A.");

    pdfFormFields.SetField("f1_10(0)", "Benefield");

    pdfFormFields.SetField("f1_11(0)", "532");

    pdfFormFields.SetField("f1_12(0)", "12");

    pdfFormFields.SetField("f1_13(0)", "1234");

 

    // The form's checkboxes

    pdfFormFields.SetField("c1_01(0)", "0");

    pdfFormFields.SetField("c1_02(0)", "Yes");

    pdfFormFields.SetField("c1_03(0)", "0");

    pdfFormFields.SetField("c1_04(0)", "Yes");

 

    // The rest of the form pdfFormFields

    pdfFormFields.SetField("f1_14(0)", "100 North Cujo Street");

    pdfFormFields.SetField("f1_15(0)", "Nome, AK  67201");

    pdfFormFields.SetField("f1_16(0)", "9");

    pdfFormFields.SetField("f1_17(0)", "10");

    pdfFormFields.SetField("f1_18(0)", "11");

    pdfFormFields.SetField("f1_19(0)", "Walmart, Nome, AK");

    pdfFormFields.SetField("f1_20(0)", "WAL666");

    pdfFormFields.SetField("f1_21(0)", "AB");

    pdfFormFields.SetField("f1_22(0)", "4321");

 

    // Second Worksheets pdfFormFields

    // In order to map the fields, I just pass them a sequential

    // number to mark them; once I know which field is which, I

    // can pass the appropriate value

    pdfFormFields.SetField("f2_01(0)", "1");

    pdfFormFields.SetField("f2_02(0)", "2");

    pdfFormFields.SetField("f2_03(0)", "3");

    pdfFormFields.SetField("f2_04(0)", "4");

    pdfFormFields.SetField("f2_05(0)", "5");

    pdfFormFields.SetField("f2_06(0)", "6");

    pdfFormFields.SetField("f2_07(0)", "7");

    pdfFormFields.SetField("f2_08(0)", "8");

    pdfFormFields.SetField("f2_09(0)", "9");

    pdfFormFields.SetField("f2_10(0)", "10");

    pdfFormFields.SetField("f2_11(0)", "11");

    pdfFormFields.SetField("f2_12(0)", "12");

    pdfFormFields.SetField("f2_13(0)", "13");

    pdfFormFields.SetField("f2_14(0)", "14");

    pdfFormFields.SetField("f2_15(0)", "15");

    pdfFormFields.SetField("f2_16(0)", "16");

    pdfFormFields.SetField("f2_17(0)", "17");

    pdfFormFields.SetField("f2_18(0)", "18");

    pdfFormFields.SetField("f2_19(0)", "19");

 

    // report by reading values from completed PDF

    string sTmp = "W-4 Completed for "pdfFormFields.GetField("f1_09(0)") + " "pdfFormFields.GetField("f1_10(0)");

    MessageBox.Show(sTmp, "Finished");

 

    // flatten the form to remove editting options, set it to false

    // to leave the form open to subsequent manual edits

    pdfStamper.FormFlattening = false;

 

    // close the pdf

    pdfStamper.Close();

} 

 

To finish up the PDF, it is necessary to determine whether or not additional edits will be permitted to the PDF after it has been programmatically completed. This task is accomplished by setting the FormFlattening value to true or false. If the value is set to false, the resulting PDF will be available for edits, if the value is set to true, the PDF will be locked against further edits.

 

Once the form has been completed, the PDF stamper is closed and the function terminated.

 

That wraps up the discussion of the form based demo project.
 

Summary

This article described an approach to populating a PDF document with values programmatically; this functionality was accomplished using the iTextSharp DLL.  

Further, the article described an approach for mapping the fields contained in PDF and may be useful if one is dealing with a PDF authored elsewhere and if the programmer does not have access to Adobe Professional or Adobe Designer. The iTextSharp library is a powerful DLL that supports authoring PDFs as well as using in the manner described in this document; however, when authoring a PDF, it seems that it would be far easier to produce a nice document using the visual environment made available through the use of the Adobe tools.  Having said that, if one is dynamically creating PDFs with variable content, the iTextSharp library does provide the tools necessary to support such an effort; with the library, one can create and populate a PDF on the fly.
 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Scott Lysle
Freelance software developer residing in Alabama. Bachelors, Masters Degrees from Wichita State University. I spent the first half of my career working on aircraft controls and displays and in that time I worked on the cockpits for the OH-58 AHIP, the AH-1W, the V-22, the F-22, the C-130J, the C-5 AMP, AWACS, JPATS, and a few others. Since 1997 I have been largely involved with Windows and web development, GIS application development, consumer electronics development (embedded linux/java), but still sometimes work on aircraft and military projects, the most recent of which was the presidential transport helicopter. I tend to work primarily with C/C++, Java, VB, and C#.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
Doesn't work with my pdf by D On March 4, 2008
Hi, I tried your code and it worked fine. For some reason it didnot work with my pdf. I've an editable form similar to your W4. I could not see the names of any of the textboxes or checkboxes in the textbox. Can you help. Thanks.
Reply | Email | Modify 
Re: Doesn't work with my pdf by Scott On March 5, 2008
Well, it could be that the form does that you are using does not actually having any controls contained within it.  It is possible to layout a PDF without using any controls at all; such forms would have been designed to print and might use rectangles instead of checkboxes and lines instead of textboxes.  The surest way to tell would be to open the pdf in acrobat and see if you can edit the form from acrobat directly.  If not, you'd need the adobe tools to add in the controls you need in order to make it something that could be editted in code.
Reply | Email | Modify 
Re: Re: Doesn't work with my pdf by D On March 5, 2008

Is there a way of keeping the form editable so that the user can save the form itself and not the copy of it?

Reply | Email | Modify 
Re: Re: Re: Doesn't work with my pdf by Scott On March 6, 2008
When you open the PDF you generally open the original as a template and then save a version of that document as the marked up copy of the original; this protects the original.  I did not try it out but it seems if you make the target (saved version) the path to the original it should overwrite it (that is, use the same path for both the template and the saved version). 
Reply | Email | Modify 
E-signature Within PDF documents by L On September 10, 2008
Suppose I'm trying to sign pdf documents with your DLL. Is it possible to do it automatically (signatures reside on the computer). Thank you in advance.
Reply | Email | Modify 
Fill in PDF Form Fields using the Open Source iTextSharp DLL by Olu On September 18, 2008
How can you accomplish the same task interactively? Gven that all information have to be entered as needed and not within the program. And can you make this an installation apps so that the IDE (VB 2005) is not used or needed?
Reply | Email | Modify 
Zero fields returned by Acro.Fields by L On September 23, 2008
I tried your code, but working on my pdf I got zero returned fields. the pdf is made by Acrobat 8.1. could this be a problem?
Reply | Email | Modify 
Re: Zero fields returned by Acro.Fields by Scott On December 5, 2008
More than likely there are no controls in the PDF.  If they person that built the document intended for it to be printed and filled out by hand, they probably just used text and graphics in lieu of controls.
Reply | Email | Modify 
How to add new field in existing form by Samir On December 2, 2008
Hi, I am trying to add new text field to the form but it's not working. i.e. pdfStamper.AcroFields.Fields.Add(newField, ""); Is it possible to add new field to existing form? How? Thanks in advance. Samir
Reply | Email | Modify 
Re: How to add new field in existing form by Scott On December 5, 2008
Take a look at this; it addresses creating documents:  http://www.devshed.com/c/a/Java/Creating-Simple-PDF-Files-With-iTextSharp/3/
Reply | Email | Modify 
Prepopulating PDF forms by Barry On December 23, 2008
I am new to iTextSharp (I think its a grand piece of software) and Adobe and pdf. I am trying to prepopulate pdf forms from a C# program. I am able to do this but after the form has been prepopulated it is not longer editable from Adobe Reader. I need this capability as only some of the fields are prepopulated by the the C# program and this will always be the case. Is there any way around this limitation or am I doing something incorrectly. Barry
Reply | Email | Modify 
Re: Prepopulating PDF forms by Scott On December 24, 2008

Barry:

Are you setting the stamper's form flattening property to false?  That should leave the form open to subsequent manual edits.

pdfStamper.FormFlattening = false;

 

Reply | Email | Modify 
Re: Re: Prepopulating PDF forms by Barry On December 29, 2008
Hi

Thanks for the suggestion but when I do the following:

pdfStamper.FormFlattening = false;

It makes no difference I get the message:

Please Note:  You cannot save a completed copy of this form on your computer.  If
You would like a copy for your records, please fill it in and print it.

And this defeats the purpose of having an electronic copy of the form that can be filled out.

I have several questions to ask. Can we discuss my problems away from this forum??

Later that same day.....

I have found out that when I open the file in Adobe Reader I cannot edit it (and the fields are not shaded)  but if I open the same file in Acrobat Professional and click on Advanced / Enable usage Rights in Adobe Reader, I get the message "This document already has enabled
usage rights in Adobe Reader".   I am now confused and need some answers.

Barry

Reply | Email | Modify 
Re: Re: Re: Prepopulating PDF forms by Scott On December 30, 2008
I sent an email; we will take a look.
Reply | Email | Modify 
Re: Prepopulating PDF forms by Sri On March 25, 2010
Hi Scott

I tried to populate a pdf file like u showed in the example.

" For
Each objEntry In reader.AcroFields.Fields "

in the above line it shows  " reader.AcroFields.Fields = 0 " (count = 0)

this means that there are no object fileds in my pdf file.

But i checked the pdf file it does have the objects.

i can even go change them by using advanced editing tools.

i have large number of files i cant do it one by one , i like to do it in Batch.
(doing programmatically will save me lot of time)

what could be the problem ?

Please help....


Reply | Email | Modify 
Re: Re: Re: Re: Prepopulating PDF forms by honey On June 15, 2010
can we do the same article using aspx pages where user fills in the web form and clicks submit and thwn the pdf is populated with web form fields.

Thanks in advance.

H
Reply | Email | Modify 
Re: Re: Re: Prepopulating PDF forms by Gregor On March 24, 2011
If you want to be able to edit the document afterward set the append to true (see last argument). PdfStamper(PdfReader reader, OutputStream os, char pdfVersion, boolean append) Cheers, Gregor Bruhin
Reply | Email | Modify 
C++? Does this work with MS Visual C++ 6.0? by wendell On May 22, 2009
Do you know if the DLL is compatable with Visual C++ 6.0?

wendell smith
Reply | Email | Modify 
Re: C++? Does this work with MS Visual C++ 6.0? by riya On June 17, 2010
Hi wendell,

Do you know how to use this dll in c++?

Thanks
Reply | Email | Modify 
Excellent Idea , but wondering.. by P On August 15, 2009
It's an excellent concept and more or less of a solution to something I am looking for. I was just wondering that is it possible to achieve the same result by creating aspx page where users just fill in the data and on click of a button it saves a filled PDF file. As I am trying to avoid having to install app on each and every users computer.
Reply | Email | Modify 
Setting Image Field dynamically by Tim On September 29, 2009
I was able to use your itextsharp.dll to set text fields of a pdf but I'm struggling to set the href property of an Image Field with your dll.  Any assitance with this would be appreciated. 

Thanks, Tim
Reply | Email | Modify 
not working... by Tom On November 16, 2009
I get no exceptions...  I dont see the new file being created...

string fileName = MapPath(@"docs/Recall Templates.pdf");

string newFile = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_out.pdf";

//PdfDocument doc = PdfReader.Open(fileName, PdfDocumentOpenMode.Import);

iTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(fileName);

iTextSharp.text.pdf.PdfStamper pdfStamper = new iTextSharp.text.pdf.PdfStamper(pdfReader, new System.IO.FileStream(newFile, System.IO.FileMode.Create));

iTextSharp.text.pdf.AcroFields fields = pdfReader.AcroFields;

iTextSharp.text.pdf.AcroFields.Item item = fields.GetFieldItem("title_mfr");

item.values[0] = "Tom Spines";

//fields.SetField("title_mfr", "Toms Spines");

pdfStamper.FormFlattening = true;

pdfStamper.Close();

pdfReader.Close();

Reply | Email | Modify 
Re: not working... by Tom On November 16, 2009
ok, i figured out file path issue (suprise it was my code)...

But if I use "fields.Setfield("title_mfr(0)", "test");

I get "This AcroFields instance is read-only." error.... whats up?
Reply | Email | Modify 
fill form from xml? by Sandra On January 9, 2010
I try to fill a form in pdf with data that is in xml format. In the iText examples for Java, I found a code example using xfa.fillXFAForm(). I am using C# with iTextSharp and can not find the similar method in XFAForm.

Does anyone know how to do this in C#?
Reply | Email | Modify 
Re: fill form from xml? by hdfc On July 19, 2011
we can fil any pdf using the following code. The FillCell() fuction has few parameters which embed the text in the specified co-ordinate. I am using the edit function to stamp text in the existing Doc.pdf. public void EditPDF() { try { PdfReader reader = new PdfReader(Path.Combine(Server.MapPath(“~/pdf”), “Doc.pdf”)); string sPdfName = Path.Combine(Server.MapPath(“~/pdf”), “Doc221.pdf”); //int n = reader.GetPageSize(); PdfStamper stamp = new PdfStamper(reader, new FileStream( sPdfName, FileMode.Create)); PdfContentByte over; BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); over = stamp.GetOverContent(1); //over = stamp.getUnderContent(i); /*Image img = Image.getInstance(“Blank.JPG”); img.setAbsolutePosition(170, 279); over.addImage(img); */ over.BeginText(); //over.setFontAndSize(bf, 18); //over.setTextMatrix(30, 30); //over.showText(“page ” + i); over.SetFontAndSize(bf, 10); FillCell(over, “xyzabc”, 280F, 692F); over.EndText(); stamp.Close(); reader.Close(); return; } catch (Exception e) { //e.printStackTrace(); } } public void FillCell(PdfContentByte over,String sText,float x,float y) { try { //System.out.println(sText.length()); float fx=x;; over.ShowTextAligned(1, sText, fx , y, 0f); return; } catch(Exception e) { //e.printStackTrace(); } }
Reply | Email | Modify 
problems with pdf version by James On January 17, 2011
I tried your code and was able to generate a pdf. However, instead of displaying a filled pdf form, the pdf displays this message: "To view the full contents of this document, you need a later version of the PDF viewer." Even after upgrading to the latest version of pdf, I still get this error. Any ideas why I'm running into this issue?
Reply | Email | Modify 
Thanks by Anil On June 10, 2011
Thanks this helped me.... Bravo !!!
Reply | Email | Modify 
setField doesnt work by Tolga On January 31, 2012
Hi thanks for the good introduction !!! My problem is, that the method setField doenst work!! The old values in the pdf are not change, but i get a new pdf document :S Below is my code: string pdfTemplate = @"C:\Users\taltinta\Documents\Visual Studio 2010\WebSites\Lieferantenbewertung\templates\Muster1.pdf"; string newFile = @"C:\Users\taltinta\Documents\Visual Studio 2010\WebSites\Lieferantenbewertung\templates\Muster3.pdf"; PdfReader pdfReader = new PdfReader(pdfTemplate); PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create)); AcroFields pdfFormFields = pdfStamper.AcroFields; // set form pdfFormFields // The first worksheet and W-4 form pdfFormFields.SetField("1", "a"); pdfFormFields.SetField("2", "b"); // flatten the form to remove editting options, set it to false // to leave the form open to subsequent manual edits pdfStamper.FormFlattening = false; // close the pdf pdfStamper.Close(); Thanks!
Reply | Email | Modify 
Nevron Chart
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.