Solved

Get Field names from a PDF Form

Posted on 2004-09-14
12
8,319 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Update 21-May-2015: I temporarily removed the source code to make major changes to the program. Regards, Joe In a previous Experts Exchange article, How To Rename-Move a Batch of PDF Files Based on Contents of the Files (http://www.experts-exchan…
Have you ever come up with a need of emailing only few pages of PDF file to one of yourfriend or colleague, instead of whole Adobe file? If yes, then surely you have face problems in doing that! Read this section as I have suggested multiple solutio…
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …

744 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

12 Experts available now in Live!

Get 1:1 Help Now