Mit iTextSharp kann ich alle Formularfelder abrufen, die in einem PDF-Formular vorhanden sind. Ich benutze Adobe Acrobat Reader, um die PDF zu bearbeiten, wobei jedes Feld ein Positionsattribut hat welches angibt, wo sich das PDF-Feld in einem Formular befindet.PDF-Formularfelder Positionsabfrage mit Itext
Also meine Frage ist, kann ich diesen Wert lesen?
Zum Beispiel, wenn ich ein Formularfeld Name in einem PDF-Formular habe, kann ich den Positionswert dieses Feldes, wie links 0,5 Zoll, rechts 2,5 Zoll, oben 2 Zoll, unten 2 Zoll?
Im Moment bin Abrufen mir die Formularfelder mit dem folgenden Code:
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);
}