I've been looking for old post and I found this:
"Hi Bruno!
I am developing a web-application to edit and customize PDF-form fields
(especially textfields and pushbuttons as container for images) with
the help of iText. Therefore I need information about the fields of an
existing pdf-document. The latest version of iText contains the method
getNewPushbuttonFromField(String field). With the help of this method I
can get nearly all information I need about pushbuttons. For other
fieldtypes there is no such method. I added the following method to the
AcroFields class to get the needed information for other fieldtypes:
public TextField getNewTextFieldFromField(String field) {
try {
float[] pos = getFieldPositions(field);
Rectangle box = new Rectangle(pos[1], pos[2], pos[3],
pos[4]);
TextField newTextField = new TextField(writer, box, null);
Item item = (Item)fields.get(field);
PdfDictionary dic = (PdfDictionary)item.merged.get(0);
decodeGenericDictionary(dic, newTextField);
if(newTextField.getFont() == null)
{
PdfString da =
(PdfString)PdfReader.getPdfObject(dic.get(PdfName.DA));
if (da != null)
{
Object dab[] =
splitDAelements(da.toUnicodeString());
if (dab[DA_FONT] != null)
newTextField.setText(String.valueOf(dab[DA_FONT]));
}
}
return newTextField;
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
}
As in the getNewPushbuttonFromField-method the non-public method
decodeGenericDictionary(PdfDictionary merged, BaseField tx) does the work,
and if the used font is not a DocumentFont the dab-object contains the
fontname of the DA-entry after calling the method splitDAelements(String
da).
This works fine (a lot of documents were tested). Is there something I
do not see that could cause problems? Or is it possible to add this
method to a new version?
With best regards,
Joachim
"
This method do exactly what I need. I put this code on source code of
iTextSharp to test. There's some plan to have this in a later version, because
at the class AcroFields there is a method that do like this, but for
PushButtonField
(AcroFields.GetNewPushbuttonFromField).
For now, I'll compile the iTextSharp with this method, but would be
interesting if new releases cames with a method like this, so when thre is a
new release, I don't need to insert this method again and compile the library.
Thanks
Rodrigo
Paulo Soares <[EMAIL PROTECTED]> escreveu:
Look at AcroFields source code. You'll need the pdf reference to understand
what's going on.
Paulo
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Develop
> Sent: Tuesday, March 06, 2007 4:40 PM
> To: itext-questions@lists.sourceforge.net
> Subject: [iText-questions] Get information from AcroForms
>
> Hi,
>
> I need to get information from acroforms. I need to read an
> PDF and identify textfield and buttonfiled. This I can do
> following the examples and I can get informations from positions.
> But I need get some extra information like rotation, text
> color, font name, font size, etc for textfield, and rotation,
> etc for buttonfield.
> At iTextSharp we have a class named TextField that I think
> can be filled with information from a textfiled form, but I
> don't know how to do this.
> I'm using PdfReader to open the document.
>
> Here is a peace of the code:
>
> PdfReader reader = new PdfReader("c:\\temp\\form.pdf");
> AcroFields form = reader.AcroFields;
> Hashtable fields = form.Fields;
> String key;
> foreach (DictionaryEntry de in fields)
> {
> key = de.Key.ToString();
> switch (form.GetFieldType(key))
> {
> case AcroFields.FIELD_TYPE_PUSHBUTTON:
> Console.WriteLine("Pushbutton");
> float[] positions2 = form.GetFieldPositions(key);
> for (int i = 0; i < positions2.Length; i++)
> {
> Console.WriteLine(positions2[i].ToString());
> }
> //I need more information here
> break;
> case AcroFields.FIELD_TYPE_TEXT:
> Console.WriteLine("Text");
> float[] positions = form.GetFieldPositions(key);
> for (int i = 0; i < positions.Length; i++)
> {
> Console.WriteLine(positions[i].ToString());
> }
> //I need more information here
> }
> }
>
>
> Thanks
>
> Rodrigo
>
> __________________________________________________
> Fale com seus amigos de graça com o novo Yahoo! Messenger
> http://br.messenger.yahoo.com/
>
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/
__________________________________________________
Fale com seus amigos de graça com o novo Yahoo! Messenger
http://br.messenger.yahoo.com/
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/