Solved

Get Field names from a PDF Form

Posted on 2004-09-14
12
8,615 Views
Last Modified: 2008-02-01
Hello, I'm Roberto from Italy

doen anybody knows how to extract file names from a PDF file that has a form?
 (the /T attribute isn't set)

Thank you very much in advance

Roberto
0
Comment
Question by:roburobe
  • 7
  • 4
12 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12052905
You can get the complete path and file name for the PDF file (or the URL it was loaded from) with
this.url
and, the document title with
this.title

0
 

Author Comment

by:roburobe
ID: 12052931
I'm Very sorry, I wrote a wrong word.

I'd like to get the FIELD names of the form inside the PDF file.

Thank you very much

Roberto
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12053110
I'm sorry too, I should have read the title of your question, and not just the content.

Use something like this:

for (var i = 0; i < this.numFields; i++)
{
    console.println("Field[" + i + "] = " + this.getNthFieldName(i));
}




And BTW: To get the file name, there is actually a better method to get the file name (without having to parse the URL) - just in case you ever need this:

this.documentFileName

0
 

Author Comment

by:roburobe
ID: 12072346
Sorry for my late answer.... is this Javascript?

Thank you
Roberto
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12073131
Yes.
0
 

Author Comment

by:roburobe
ID: 12073358
Please, can you send me a complete example??? I know just a very little Javascript.....

Thank you....
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12073377
First I need to know what you want to accomplish. The few lines I sent you are a complete example: When you put this into a callback for e.g. a button click, it will print all form field names to the JavaScript console in Acrobat.

Do you want the form fields in Acrobat, or in an external application? What are you planning on doing with the field names?
0
 

Author Comment

by:roburobe
ID: 12073408
Thank you.

I have a PDF file with a blank form inside. I'd like to compile that form via a web page. But I don't know the fields names and via Acrobat (not Reader) they doesn't appear.

Simply, I'd like to know the field names of the PDF Form. So I have a PDF (without any button) and a blank page. How can I "load" the PDF and watch inside it to look at these informations?

Thank you a lot

Roberto
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12073587
You don't need any special tools if you have the full version of Acrobat (with Acrobat 6, this needs to be "Professional"). Just open your PDF file, and then select the "Select Object Tool" ("Tools>Advanced Editing>Select Object Tool"). This will show all forms on the page, and you can double-click on the forms to get the form field properties.

Does this work for you? If not, I can give you a JavaScript that will add a menu item to display teh names of all form fields.
0
 
LVL 4

Accepted Solution

by:
avi247 earned 500 total points
ID: 12094266
Rob:
The pdf file you are working with must be editable i.e. you must be able to manually enter data into it. If you can do that then proceed as follows..
1. Enter data manually into each field.
2. In Acrobat, go to File> Export > Form Data. Enter name for the .fdf file.
3. An fdf file contains the name of the form fields along with the form data, and a points to the orginal pdf template. If you double click on this file, it opens up in Acrobat. You can right click on it and open it in notepad and view the name of all the fields.
4. Once you understand the structure of the fdf file (its easy), you can create it programatically (its a text file).

Refer:
http://www.planetpdf.com/mainpage.asp?WebPageID=338 
http://www.planetpdf.com/mainpage.asp?webpageid=1539#dload

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12097959
avi247, why do this extra step? You need the full version of Acrobat for your method anyway, and with the full version, when you turn on the "object select" tool, you will actually see the form names on the screen (that is, if the form fields are not so small that the full name cannot be displayed completely) or you double-click on the field and get the name from the properties dialog).

Roberto, If you only have the free Reader, you are pretty much out of luck (no way to use FDF here either). You can however open the file in the standalone - or application - version of the Enfocus Browser (http://www.enfocus.com/support/knowledgeBase/browser.php) to look at the "guts" of the PDF file to identify the form fields. If you only have one page, this is fairly easy. All  fields are in the "Annots" dictionary on the page level (set the page number in the Browser UI and then click on the "Page" button). You will see an array of form fields (e.g. [0], [1] for two fields on the page). Click on one of them, and look at the "T" dictionary entry for the name. The "FT" does contain the field type (e.g. "Btn" for a button).
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12098014
OK, you are not completely out of luck with just Reader - I promised you some JavaScript, and here it is:

Save the following lines to a file in the JavaScripts directory (e.g. c:\Program Files\Adobe\Acrobat 6.0\Reader\JavaScripts):

function listFormFields()
{
   var allFields = "";

   for (var i = 0; i < this.numFields; i++)
   {
      var newField = '"' + this.getNthFieldName(i) + '" ';
      allFields += newField;
   }
   app.alert(allFields);
}

app.addMenuItem({
   cName: "JSListFormFields",
   cUser: "List all Form Fields",
   cParent: "File",
   cExec: "listFormFields()",
   cEnable: "event.rc = (event.target != null);",
   nPos: 0,
});
// end of script

This will add a new menu item (as the first menu item) in the "File" menu. Load your document in question and then execute this menu item. You will see a list of all field names that are used in this document.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Barcode detail gets lost in PDF 3 106
pdf to word 13 78
pdf convertor 7 66
Is there a 64bit version of Adobe Acrobat XI? 2 54
Can Be Caused By Disabled Services I have encountered a problem viewing PDF files using Adobe Acrobat Reader.  For the longest time, PDFs might launch or might not.  Sometimes they took about 15 minutes to appear after launching them. After som…
This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now