Archive for August 1st, 2007

Freely fill PDF form with the help of iText or iTextSharp

iText(java version) and iTextSharp(dotnet version) are very powerful libraries to create and manipulate PDF, but this time, I just want to talk about how to fill PDF form with the help of iText or iTextSharp.

for java version, please visit http://itextdocs.lowagie.com/tutorial/#part5, there are many examples about fill or create PDF form.

for dotnet version(C#),
the easiest example is
PdfReader reader = new PdfReader("SimpleRegistrationForm.pdf");
PdfStamper stamp1 = new PdfStamper(reader, new FileStream("registered.pdf",FileMode.Create));
AcroFields form1 = stamp1.AcroFields;

form1.SetField("name", "Steven");
form1.SetField("address", "http://blog.rubypdf.com");
form1.SetField("postal_code", "200051");
form1.SetField("email", "rocsky@gmail.com");
stamp1.Close();
reader.Close();

and if you want to fill CJK(Chinese, Japanese and Korean) characters to PDF from, have a look the following code,

BaseFont.AddToResourceSearch("iTextAsian-1.0.dll");
BaseFont.AddToResourceSearch("iTextAsianCmaps-1.0.dll");
BaseFont font = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
//if you want to use truetype fonts
//BaseFont font = BaseFont.CreateFont("c:\\windows\\fonts\\STSONG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

PdfReader reader = new PdfReader("SimpleRegistrationForm.pdf");
PdfStamper stamp1 = new PdfStamper(reader, new FileStream("registered.pdf",FileMode.Create));

AcroFields form1 = stamp1.AcroFields;

//if the field you want to fill CJK characters, but the font it used does not support cjk, you need modify it before fill.
form1.SetFieldProperty("name","textfont",font,null);

//fill the form now
form1.SetField("name", "小李");
form1.SetField("address", "http://blog.rubypdf.com");
form1.SetField("postal_code", "200051");
form1.SetField("email", "rocsky@gmail.com");
stamp1.Close();
reader.Close();

related resources from my Chinese Blog and my free asp.net hosting,

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • BlinkList
  • blogmarks
  • blogtercimlap
  • connotea
  • DotNetKicks
  • Fark
  • Fleck
  • Gwar
  • Haohao
  • IndianPad
  • Internetmedia
  • LinkaGoGo
  • MyShare
  • Netscape
  • NewsVine
  • Rec6
  • Reddit
  • Scoopeo
  • Slashdot
  • StumbleUpon
  • Technorati
  • Webride

install YetAnotherForum.NET on free asp.net 2.0 hosting-aspspider.net

YetAnotherForum.NET (YAF) is a Open Source discussion forum or bulletin board system for web sites running ASP.NET. The latest version is ASP.NET v2.0 with a Microsoft SQL Server backend. The full C# source code is available licensed as GPL.

Yesterday, some friends talked about set up a asp.net forum, and one of them recommended YAF, I googled it today, and tried to installed on my free asp.net 2.0 hosting, aspspider.net(it does not offer hosting to new user). It is very easy to install,

  • download from http://sourceforge.net/project/showfiles.php?group_id=90539
  • log on http://www.aspspider.net/cp/
  • upload YAF-v1.9.0-FINAL-BIN.zip and uncompress,
  • create a blank database at local, for example name yaf, so you get yaf.mdf and yaf_log.ldf, just upload yaf.mdf to database folder and forget yaf_log.ldf.
  • attach yaf.mdf as tonyfox_yaf(because my usename is tonyfox, so the prefix is tonyfox_)
  • find default.config and rename to web.config
  • edit the connect string in web.config, just like this,
    .\SQLExpress;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=tonyfox_yaf
  • install YAF now,http://aspspider.net/tonyfox/install/

Feel free to visit my demo,
http://aspspider.net/tonyfox/

related resource,

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • BlinkList
  • blogmarks
  • blogtercimlap
  • connotea
  • DotNetKicks
  • Fark
  • Fleck
  • Gwar
  • Haohao
  • IndianPad
  • Internetmedia
  • LinkaGoGo
  • MyShare
  • Netscape
  • NewsVine
  • Rec6
  • Reddit
  • Scoopeo
  • Slashdot
  • StumbleUpon
  • Technorati
  • Webride