- We need prepare tools, "Adodb Acrobat" please download it and install it.
- open the adodb acrobat . make an new pdf file (you can make it form image, word and exgist pdf file)
- find Form toolbar from menu.
- drop the text field (文本域)to work panel, then set some properties name...
ok looke the code
How fill the real text to text field , we need use PdfStamper class
Example :
PdfReader reader = new PdfReader(path);
PdfStamper stamper = new PdfStamper(reader, stream);
AcroFields af = stamper.AcroFields;
af.SetField("CurrentDate", DateTime.Now.ToString());
stamper.Close();
return stream;
PdfStamper stamper = new PdfStamper(reader, stream);
AcroFields af = stamper.AcroFields;
af.SetField("CurrentDate", DateTime.Now.ToString());
stamper.Close();
return stream;
BaseFont arial = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font font = new Font(arial,9,Font.NORMAL);
float[] fl = af.GetFieldPositions("CurrentDate");
Rectangle rec = new Rectangle(fl[1], fl[2], fl[3], fl[4]);//左下角右上角
PdfContentByte cb = stamper.GetOverContent((int)fl[0]);
PdfTemplate template = cb.CreateTemplate(rec.Width, rec.Height);
template.BeginText();
template.SetColorFill(Color.WHITE);
template.SetFontAndSize(arial, 9);
template.ShowText(DateTime.Now().ToString());
template.EndText();
Font font = new Font(arial,9,Font.NORMAL);
float[] fl = af.GetFieldPositions("CurrentDate");
Rectangle rec = new Rectangle(fl[1], fl[2], fl[3], fl[4]);//左下角右上角
PdfContentByte cb = stamper.GetOverContent((int)fl[0]);
PdfTemplate template = cb.CreateTemplate(rec.Width, rec.Height);
template.BeginText();
template.SetColorFill(Color.WHITE);
template.SetFontAndSize(arial, 9);
template.ShowText(DateTime.Now().ToString());
template.EndText();
Some times we need replace the image .
ok, you can drop the button tool, then config it
string ImagePath="";
iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(ImagePath));
if (gif != null)
{
PushbuttonField bf = af.GetNewPushbuttonFromField("Image");
bf.Image = gif;
af.ReplacePushbuttonField("Image", bf.Field);
}
iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(ImagePath));
if (gif != null)
{
PushbuttonField bf = af.GetNewPushbuttonFromField("Image");
bf.Image = gif;
af.ReplacePushbuttonField("Image", bf.Field);
}
//float[] fl = af.GetFieldPositions("Image");
//PdfContentByte cb = stamper.GetOverContent((int)fl[0]);
//Rectangle rec = new Rectangle(fl[1], fl[2], fl[3], fl[4]);//左下角右上角
//gif.ScaleToFit(rec.Width, rec.Height);
//gif.SetAbsolutePosition(fl[1] +(rec.Width - gif.ScaledWidth) / 2, fl[2] +(rec.Height - gif.ScaledHeight) / 2);
//cb.AddImage(gif);
//PdfContentByte cb = stamper.GetOverContent((int)fl[0]);
//Rectangle rec = new Rectangle(fl[1], fl[2], fl[3], fl[4]);//左下角右上角
//gif.ScaleToFit(rec.Width, rec.Height);
//gif.SetAbsolutePosition(fl[1] +(rec.Width - gif.ScaledWidth) / 2, fl[2] +(rec.Height - gif.ScaledHeight) / 2);
//cb.AddImage(gif);
So we can easy to build some pdf template
lovebanyi lookcode.net 风云