iTextSharpを使用すると、PDFフォームに存在するすべてのフォームフィールドを取得できます。PDFを編集するにはAdobe Acrobat Readerを使用しています。すべてのフィールドには位置属性がありますこれは、PDFフィールドがフォーム内に存在する場所を示します。PDFフォームのフィールド位置検索Itext
私の質問は、その値を読むことができますか?
例えば、PDFフォームにフォームフィールドの名前がある場合、左の0.5インチ、右の2.5インチ、上の2インチ、下の2インチのように、このフィールドの位置の値を取得できますか?
は今、私は以下のコードでフォームフィールドを取得しています:
string pdfTemplate = @"D:\abc.pdf";
PdfReader reader = new PdfReader(pdfTemplate);
var fields = reader.AcroFields;
int ffRadio = 1 << 15; //Per spec, 16th bit is radio button
int ffPushbutton = 1 << 16; //17th bit is push button
int ff;
//Loop through each field
foreach (var f in fields.Fields)
{
String type = "";
String name = f.Key.ToString();
String value = fields.GetField(f.Key);
//Get the widgets for the field (note, this could return more than 1, this should be checked)
PdfDictionary w = f.Value.GetWidget(0);
//See if it is a button-like object (/Ft == /Btn)
if (!w.Contains(PdfName.FT) || !w.Get(PdfName.FT).Equals(PdfName.BTN))
{
type = "T";
}
else
{
//Get the optional field flags, if they don't exist then just use zero
ff = (w.Contains(PdfName.FF) ? w.GetAsNumber(PdfName.FF).IntValue : 0);
if ((ff & ffRadio) == ffRadio)
{
//Is Radio
type = "R";
}
else if (((ff & ffRadio) != ffRadio) && ((ff & ffPushbutton) != ffPushbutton))
{
//Is Checkbox
type = "C";
}
else
{
//Regular button
type = "B";
}
}
//MessageBox.Show(type + "=>" + name + "=>" + value);
FormFields fld = new FormFields(name, type, value, "inputfield" +form_fields.Count);
form_fields.Add(fld);
if (type.Equals("T"))
addContent(form_fields.Count);
}