These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to make Title same as file name in Document Properties

bphillips
Registered: Feb 12 2008
Posts: 5
Answered

We will be having several hundred PDFs each month that will need a name in the Title field of Document Properties. We create the PDFs out of Quark and run them through Distiller and they come out with this field blank. I found a way in Batch Processing in Acrobat to edit the other data in the document properties, but am not sure how to go about getting the Title to be the same as the File name as this will change for each document. Is there some command that I can enter in the batch to accomplish this? I'm thinking something similar to Word where you can put "&File" to get it to include the file name in the header area. Is there something like that in Acrobat that will automatically put the file name as the Title? Thanks for any and all help!

My Product Information:
Acrobat Pro 7.0.9, Macintosh
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
There are 3 docuemnt properties in version 7 that contain the file name.

this.path is the full path to the file in version 3.01 and above

this.URL is the full url to the file in version 5 and above

this.documentFileName is the file name and extension in version 7 and above

To see what these methods reutrn and how to split the properties, run the following commands in the JavaScript Debugger:

console.println("path: " + this.path);var aPath = this.path.split("/"); // make path an arrayconsole.println("file name & extension: " + aPath[aPath.length -1]); // get last element of arrayvar aPathNameExt = aPath[aPath.length -1].split("."); // get array of file name and extensionconsole.println("file name: " + aPathNameExt[0]); // get file name from arrayconsole.println("");console.println("URL: " + this.URL);var aURL = this.URL.split("/") // make URL an arrayconsole.println("file name & extension: " + aURL[aURL.length - 1]); // get last element of arrayvar aURLNameExt = aURL[aURL.length -1].split("."); // get array of file name and extensionconsole.println("file name: " + aURLNameExt[0]); // get file name from arrayconsole.println("");console.println("documentFileName: " + this.documentFileName);var aDocumentFileName = this.documentFileName.split("."); // make document file name an arrayconsole.println("file name: " + aDocumentFileName[0]);

this.info.Title will access the meta data title field

So in version 7 one can use in the batch sequence to add the file name less the file extension:

var aDocumentFileName = this.documentFileName.split("."); // make document file name an arraythis.info.Title =  aDocumentFileName[0]; // make title the file name

Versions prior to 7 can use:

var aPath = this.path.split("/"); // make path an arrayvar aPathNameExt = aPath[aPath.length -1].split("."); // get array of file name and extensionthis.info.Title = aPathNameExt[0]; // get file name from array

George Kaiser

bphillips
Registered: Feb 12 2008
Posts: 5
Thank you that did the trick!!! You have save me many hours of work and much hair loss. Thank you so much!!

Is there someplace where this type of code is documented or where there are preset tasks such as this that you can copy/paste when needed?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Here are some of the resouces I use:

Documentation available from Adobe:

Acrobat SDK; http://www.adobe.com/devnet/acrobat/
Acrobat JavaScript Documentation: http://www.adobe.com/devnet/acrobat/javascript.php
Acrobat FDF Toolkit: http://www.adobe.com/devnet/acrobat/fdftoolkit.php
PDF Refernce: http://www.adobe.com/devnet/pdf/pdf_reference.php

The above sites include additional links to other PDF infromation.

Books:
Adobe Acrobat Bible series by Ted Padova
Adobe Arcobat Tips and Tricks by Donna L. Baker
Extending Acrobat Forms with JavaScirpt by John Deubert
Creating Dynamic Forms with Adobe LiveCycle Designer by J. P. Terry

Adobe Sponsored forums:
Acrobat User-to-User forums: http://www.adobeforums.com/cgi-bin/webx/.3bbeda8b/
Acrobat User Community: http://www.acrobatusers.com/

Other Forums:
Planet PDF Fourms: http://forum.planetpdf.com/wb/default.asp

Other PDF Sites:
Planet PDF: http://www.planetpdf.com/
Windjack Solutions: http://www.windjack.com/
Ted's Homepage: http://www.west.net/~ted
Abracadabra PDF: http://www.abracadabrapdf.net/index.php?lng=en
NitroPDF: http://www.nitropdf.com/index.asp
D.P. Story (Acrotex): http://www.acrotex.net.
PDF Zone: http://www.pdfzone.com/

JavaScirpt:
JavaScript Central: http://devedge-temp.mozilla.org/central/javascript/index_en.php

Some of the responders, experts, and columnist are included in this lsit because of their personal, professional, and commercial contributions to the development and evangilasation of the PDF format and Acrobat product.

George Kaiser

lmeller
Registered: Mar 4 2011
Posts: 1
In my Acrobat 8 plugin (C++) i need to make Title same as file name in Document Properties.
Can you please advice what API to use? Is there any code example?
Thank you.

A6P6cUvf4X

bphillips
Registered: Feb 12 2008
Posts: 5
Here is what I did. Under the Advanced Menu, Document Processing, Batch Processing, choose New Sequence and give your sequence a name. In the Edit Batch Sequence box click Select Commands and from the list that appears on the left choose Execute JavaScript and Add it to the list on the right. Double-click Execute JavaScript after it appears in the panel on the right and a window opens asking you to enter the script. Copy and past the following:

var aDocumentFileName = this.documentFileName.split("."); // make document file name an array
this.info.Title = aDocumentFileName[0]; // make title the file name

Click Ok and then Ok again to take you back to the Edit Batch Sequence box. Choose the options you want for Run Commands On, Select Output location and Output Options and then click OK. Now you are back to the Batch Processes dialog box and ready to run the new process on your files. Select your newly created Sequence from the list and click Run Sequence and navigate to the files you want to change. Note that the files cannot be open in Acrobat in order to run the Batch Processing function on them.

Hope that helps!
Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
No, nothing…
Sorry I can't delete this post.