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

how to display a filename?

cooli
Registered: May 28 2008
Posts: 11
Answered

Hi
i have to batch a lot of scanned pdf documents(annual reports), but i need to add front page with the name of the company and the year. So my question is there a way to get the filename of pdf file (for examle Schnieder_Logisics_AnnualReport_2006_EN)?

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Depending on what version of Acrobat that you have you can use the "documentFileName" propterty (version 6 or above) or the "URL" property of the 'Doc" object.

George Kaiser

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, the file name is stored in the document property "documentFileName". You'll find this and more in the Acrobat JavaScript Reference, which you can download from here:

http://www.adobe.com/devnet/acrobat/javascript.php

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

cooli
Registered: May 28 2008
Posts: 11
I see... but it seems complicated and unfortunally i'm noob. couse i need not the all name, but part of it. for ex. from file name "Schnieder_Logisics_AnnualReport_2006_EN.pdf", i need to make a batch sequance, that creates first page with text "Schnieder Logisics" and next line "Annual Report 2006". any ideas how to do that?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
If you are going to use a batch process or to add this information, you have to have a standard naming structure. Since the "documentFileName" property end in the 4 characters o4 ".PDF", one can use the some methods of JavaScript's "String" object to get the length of the string and extract a specific length of the string to get rid of the ".PDF". The following script can be run from the JavaScript console or put inton a button or custom calculation script and will disply information needed to build the title.

var sFileName = this.documentFileName; // get the file name
var fLength = sFileName.length; // get the length for File name and extension
var sName = sFileName.substring(0, fLength - 4); // get the sub string of the name only

// show what we have so far
console.show();
console.clear();
console.println("File Name & Extension: " + sFileName);
console.println("Length of full name: " + fLength);
console.println("Name only: " + sName);
console.println("");
console.println("Elements of name:");

var aName = sName.split("_"); // convert into an array, "_" terminates an element
for (i = 0; i

George Kaiser

cooli
Registered: May 28 2008
Posts: 11
thanks a lot!
cooli
Registered: May 28 2008
Posts: 11
some documentFileNames have bigger lenght (more than 4 words). my code looks like this:

var Rect = this.getPageBox("Crop");
this.newPage(0, Rect[2], Rect[1]);

var Bbox = this.getPageBox("Crop");
var inch = 72;


var f = this.addField("Text1", "text", 0,
[72, Bbox[1]-inch, Bbox[2]-inch, Bbox[1]-2*inch ] );

f.strokeColor = color.black;
f.richText = true;
f.multiline = true;

var spans = new Array();
var sFileName = this.documentFileName;
var myRegExp = /Jaarverslag/;
var myText = sFileName;
var fLength = sFileName.length;
var sName = sFileName.substring(0, fLength - 9);
var aName = sName.split("_");
for (var i = 0; i