You can use Adobe Acrobat professional to create a PDF form template. Put a
TextField and give a name for that as text1.Then set the formatting.
In the c# code follow these steps
using
System;
using
System.Collections;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Xml;
using
System.Xml.Linq;
/* reference to
the itextsharp */
using
iTextSharp.text;
using
iTextSharp.text.pdf;
using
System.Text;
namespace
ItextSharpTut
{
public class
UtilityMethod
{
public void
generatePDF()
{
try
{
string pdfTemplate = System.Web.HttpContext.Current.Server.MapPath("~/doc/new.pdf");
PdfReader
pdfReader = null;
// Create the form filler
FileStream
pdfOutputFile = new
FileStream(pdfTemplate, FileMode.Create);
string path = System.Web.HttpContext.Current.Server.MapPath("~/doc/template.pdf");
pdfReader = new PdfReader(path);
PdfStamper pdfStamper = null;
pdfStamper = new PdfStamper(pdfReader, pdfOutputFile);
// Get the form fields
AcroFields testForm = pdfStamper.AcroFields;
testForm.SetField("text1",
"Lasantha");
PdfContentByte overContent = pdfStamper.GetOverContent(1);
pdfStamper.FormFlattening = true;
pdfStamper.Close();
pdfReader.Close();
}
catch (Exception
ex)
{
throw ex;
}
}
}
}
Enjoy it.
santhosh emmadiPosted Oct 14, 2014, 7:24 AM
Hi Am geeting the error like this ""no message found for 1.not.found.as.resource type 1 font 1" in .afm files. even the file exists. here i am using itextlibrary instead of dll file.
Former memberPosted Nov 28, 2013, 3:06 AM
You can add text into existing pdf document or newly created pdf file by using Aspose.Pdf for .NET. Check out the link for code: http://www.aspose.com/docs/display/pdfnet/Add Text in an Existing PDF File