<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jesal gadhia &#187; itextsharp</title>
	<atom:link href="http://jesal.us/tag/itextsharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://jesal.us</link>
	<description></description>
	<lastBuildDate>Thu, 14 Jul 2011 18:51:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Create PDF Forms using iTextSharp</title>
		<link>http://jesal.us/2008/10/create-pdf-forms-using-itextsharp/</link>
		<comments>http://jesal.us/2008/10/create-pdf-forms-using-itextsharp/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 17:31:10 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[itextsharp]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=98</guid>
		<description><![CDATA[Generating PDF forms in .NET has always been somewhat messy and complicated. I&#8217;ve seen people convert raw HTML to PDF or adding and formatting form elements to a PDF doc in code behind, etc. All those methods are highly time consuming and tricky. Easiest way to create PDF Forms is by using iTextSharp (open source) [...]]]></description>
			<content:encoded><![CDATA[<p>Generating PDF forms in .NET has always been somewhat messy and complicated. I&#8217;ve seen people convert raw HTML to PDF or adding and formatting form elements to a PDF doc in code behind, etc. All those methods are highly time consuming and tricky. Easiest way to create PDF Forms is by using <a href="http://itextsharp.sourceforge.net/" target="_blank">iTextSharp</a> (open source) and <a href="http://www.adobe.com/products/livecycle/designer/" target="_blank">Adobe LiveCycle Designer</a>. </p>
<p>You can just create your custom form template using LiveCycle and then data bind the form fields using iTextSharp like this:</p>
<pre name="code" class="c-sharp:nogutter">
User user = UserData.GetUserByID(userID);
string randomFileName = Helpers.GetRandomFileName();
string formTemplate = Server.MapPath("~/FormTemplate.pdf");
string formOutput = Server.MapPath(string.Format("~/downloads/Forms/Form-{0}.pdf", randomFileName));

PdfReader reader = new PdfReader(formTemplate);
PdfStamper stamper = new PdfStamper(reader, new System.IO.FileStream(formOutput, System.IO.FileMode.Create));
AcroFields fields = stamper.AcroFields;

// set form fields
fields.SetField("Date", DateTime.Now.ToShortDateString());
fields.SetField("FirstName", user.FirstName);
fields.SetField("LastName", user.LastName);
fields.SetField("Address1", user.Address1);
fields.SetField("Address2", user.Address2);
fields.SetField("City", user.City);
fields.SetField("State", user.State);
fields.SetField("Zip", user.Zip);
fields.SetField("Email", user.Email);
fields.SetField("Phone", user.Phone);

// set document info
System.Collections.Hashtable info = new System.Collections.Hashtable();
info["Title"] = "User Information Form";
info["Author"] = "My Client";
info["Creator"] = "My Company";
stamper.MoreInfo = info;

// flatten form fields and close document
stamper.FormFlattening = true;
stamper.Close();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/10/create-pdf-forms-using-itextsharp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

