Skip navigation
Currently Being Moderated

Print File Name with pdf Document

Aug 30, 2006 10:52 AM

In order to have an audit trail / track a document, I want to print the file name as a header or footer when printing the documents. How can this be done?
 
Replies 1 2 3 4 Previous Next
  • Currently Being Moderated
    Nov 9, 2006 9:14 AM   in reply to (Lloyd_G_Guenther)
    I have exactly the same question; it's unimaginable that this can't be done.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 9, 2006 9:41 AM   in reply to (Lloyd_G_Guenther)
    you can do it with a JavaScript.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2006 5:15 AM   in reply to (Lloyd_G_Guenther)
    Add some JavaScript to your document as a "Will print" event.

    Details in the Acrobat JavaScript Guide.

    Leonard
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2006 8:26 AM   in reply to (Lloyd_G_Guenther)
    Ok, thanks, but I don't know JavaScript, and even if I did your answer suggests that it needs to be done de novo for each document for which you need this information. We create many documents each day from a web-based banking application, and it would be great if Acrobat would simply handle this. I'm amazed Adobe hasn't built this in.

    If I've misunderstood the custom nature of your solution, please let me know. And if you'd care to toss in some JavaScript, great!

    :)

    Thanks.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2006 10:46 AM   in reply to (Lloyd_G_Guenther)
    I read your question as how to do that for a particular document - so yes, the embedded JavaScript would need to be included in that document. You could certainly have this done on the server as well, as part of your creation process.

    As to have Acrobat do this - although Acrobat itself doesn't include this functionality - I believe there are some 3rd party plugins for Acrobat that can add this.

    Leonard
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2006 1:13 PM   in reply to (Lloyd_G_Guenther)
    Attached a simple JS that will do it. Copy it into Notepad and save it in your Acrobat \Javascript folder. Next time you start Acrobat you will a have menuitem "Print with Footer" direct above Print.

    It put the values into fields at the footer. That may took some time. Then it displays the print-dialog and finaly you can choose if you want to remove the fields or not.

    Enjoy, Reinhard

    PrintWithFooter.js
    -------------------------------

    app.addMenuItem({cName:"Print with Footer", cParent:"File", nPos:20, cExec:"PrtFooter();"});

    //Print bookmarked Pages
    function PrtFooter()
    {

    for (var p = 0; p < this.numPages; p++)

    {

    var fd = this.addField("Date", "text", p, [10,10, 300,28]);
    fd.textSize=8; fd.value = "Date: " + util.printd("yyyy/mmm/dd", new Date()) + " (" + this.path +")"

    var fp = this.addField(String("page"+p+1), "text", p, [330,10,280,28]);

    fp.textSize=8; fp.value = "Page: " + String(p+1)+ "/" + this.numPages;

    }

    app.execMenuItem("Print");

    var OK = app.alert("Delete Date / Filename?",2,2);

    if (OK == 4) {

    var x = removeField("Date");

    for (var p = 0; p < this.numPages; p++)

    {

    var x = removeField(String("page"+p+1));

    } }

    }
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2006 5:30 PM   in reply to (Lloyd_G_Guenther)
    Thank you Reinhard! You were kind to do this; but if I may ask a favor, can I get a version that just prints the date and the file name? I don't need the file path, since it's very long anyway.

    Also, this script crashes when one chooses the "yes" option on the remove dialog.

    Many thanks
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2006 1:55 PM   in reply to (Lloyd_G_Guenther)
    Attached an updated Script. It gives you a menu for Set/Remove Footer. Then you can Set - Print - Remove.

    HTH, Reinhard

    PrintWithFooter.js
    -------------------------------

    app.addSubMenu({ cName: "Footer",cUser: "Set/Remove Footer", cParent: "File", nPos: 20 });

    app.addMenuItem({ cName: "Set Date Time (Filename)", cParent: "Footer", cExec: "SetFooter(1)"});
    app.addMenuItem({ cName: "Set Page ", cParent: "Footer", cExec: "SetFooter(2)"});
    app.addMenuItem({ cName: "Set Both", cParent: "Footer", cExec: "SetFooter(3)"});

    app.addMenuItem({ cName: "-------------------------------", cParent: "Footer",cExec: "{}"});

    app.addMenuItem({ cName: "Remove Date Time (Filename)", cParent: "Footer", cExec: "RemoveFooter(1)"});
    app.addMenuItem({ cName: "Remove Page", cParent: "Footer", cExec: "RemoveFooter(2)"});
    app.addMenuItem({ cName: "Remove Both", cParent: "Footer", cExec: "RemoveFooter(3)"});

    function SetFooter(ARG)
    {
    var re = /.*\/|\.pdf$/ig;
    var FileNM = this.path.replace(re,"")+".pdf";
    var Path = this.path;
    var AcDate = new Date();
    for (var p = 0; p < this.numPages; p++)

    {

    if (ARG==1 || ARG==3) {var fd = this.addField("xftDate", "text", p, [30,15, 290,30]);

    fd.textSize=6; fd.value = util.printd("yyyy/mmm/dd, HH:MM", AcDate) + " (" + FileNM +")"; }

    if (ARG==2 || ARG==3){var fp = this.addField(String("xftPage"+p+1), "text", p, [350,15,300,30]);

    fp.textSize=6; fp.value = "Page: " + String(p+1)+ "/" + this.numPages; }

    } }

    function RemoveFooter(ARG)
    {

    if (ARG==1 || ARG==3) {var x = this.removeField("xftDate");}

    if (ARG==2 || ARG==3) {for (var p = 0; p < this.numPages; p++)

    {

    var x = this.removeField(String("xftPage"+p+1)); }

    } }
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2006 5:17 AM   in reply to (Lloyd_G_Guenther)
    OK! Did a little bit more so it is usable for myself.

    Now you can choose if you want to have the "Date Time (Filename" footer want to have left, center, or right aligned.

    The code has been updated:
    - now it really cnter the boxes page for page.
    - the first box (Date ...) uses the total width of the page. So it also useable if you want to have a selfmade footer note, something like "First Draft from ....". You have only to edit one box on one page, then it will be displayed on all pages.

    - if you want to remove you can use allways "Remove both". It's only work a little bit longer in bigg files.

    br, Reinhard

    PS to other scripters: If someone has time he may improve the script.
    The general settings could be done on a extra page (like general Dateformat, general Texthigh, ..... Then this can saved in global.js. So all the user defined settings are stored and retrieveable. That would Adobe save work. Adobe should set up a "Acrobat Scripts & Scraps" forum, where (freetime-)scripter can publish and discuss scripts.

    Edit: ... and where it is also possible to publish scripts without to have to format by yourselft, so that it is readable!

    SetRemoveFooter.js (<-Save in folder ...\javascript)

    -----------------------------------------------


    // SetRemoveFooter

    app.addSubMenu({ cName: "Footer",cUser: "Set/Remove Footer", cParent: "File", nPos: 20 });


    app.addMenuItem({ cName: "Set Date Time (Filename)", cParent: "Footer", cExec: "SetFooter(1)"});

    app.addMenuItem({ cName: " -> Set Date .... centered", cParent: "Footer", cExec: "SetFooter(2)"});

    app.addMenuItem({ cName: " -> Set Date .... right", cParent: "Footer", cExec: "SetFooter(3)"});

    app.addMenuItem({ cName: "Set Page ", cParent: "Footer", cExec: "SetFooter(4)"});

    app.addMenuItem({ cName: "Set Both", cParent: "Footer", cExec: "SetFooter(5)"});


    app.addMenuItem({ cName: "-------------------------------", cParent: "Footer",cExec: "{}"});


    app.addMenuItem({ cName: "Remove Both", cParent: "Footer", cExec: "RemoveFooter(5)"});

    app.addMenuItem({ cName: "Remove Date Time (Filename)", cParent: "Footer", cExec: "RemoveFooter(1)"});

    app.addMenuItem({ cName: "Remove Page", cParent: "Footer", cExec: "RemoveFooter(4)"});


    //Set/remove Footer
    function SetFooter(ARG)
    {

    var re = /.*\/|\.pdf$/ig;

    var FileNM = + this.path.replace(re,"")+".pdf";

    var Path = this.path;

    var AcDate = new Date();
    var AcDateFormat = "yyyy/mmm/dd HH:MM"

    var Box2Width = 50

    for (var p = 0; p < this.numPages; p++)

    {

    var aRect = this.getPageBox("Crop",p);

    var TotWidth = aRect[2] - aRect[0]

    if (ARG<=3 || ARG==5)

    {var fd = this.addField("xftDate", "text", p, [30,15, TotWidth-30-30,30]);

    fd.value = util.printd(AcDateFormat, AcDate) + " (" + FileNM +")";

    fd.textSize=6; fd.readonly = true;

    if (ARG==1){ fd.alignment="left" };

    if (ARG==2){ fd.alignment="center" };

    if (ARG==3){ fd.alignment="right" };

    }

    if (ARG==4 || ARG==5)

    {var bStart=(TotWidth/2)-(Box2Width/2)

    var bEnd=((TotWidth/2)+(Box2Width/2))

    var fp = this.addField(String("xftPage"+p+1), "text", p, [bStart,30,bEnd,15]);

    fp.value = "Page: " + String(p+1)+ "/" + this.numPages;

    fp.textSize=6; fp.readonly = true;

    fp.alignment="center";

    }

    } }


    function RemoveFooter(ARG)

    {

    if (ARG<=3 || ARG==5) {var x = this.removeField("xftDate");}

    if (ARG==2 || ARG==5) {for (var p = 0; p < this.numPages; p++)

    {

    var x = this.removeField(String("xftPage"+p+1)); }

    } }
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2006 10:01 AM   in reply to (Lloyd_G_Guenther)
    Hi Reinhard,

    Thanks for working on this. However, this script does not work, because the "Set/Remove Footer" submenu does not appear in my File menu (the previous version worked fine). I have carefully copied and pasted your script into a new .js file in the \javascripts folder. What could I be doing wrong?

    Jeff
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2006 1:33 PM   in reply to (Lloyd_G_Guenther)
    I've edited above script and now it should work.

    br, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2006 3:09 PM   in reply to (Lloyd_G_Guenther)
    Thanks. Can you post it?

    Regards

    Jeff
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 17, 2006 12:34 AM   in reply to (Lloyd_G_Guenther)
    I think there is no need. I copied it out and in and it works fine for me (AAr5).

    However you may state where to sent to and you will get it.

    br, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 17, 2006 12:20 PM   in reply to (Lloyd_G_Guenther)
    Just remembered to some Webspace I have. You can download from:

    http://www.Refob.de/downloads/acrobat/SetRemoveFooter.js

    HTH Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 17, 2006 12:30 PM   in reply to (Lloyd_G_Guenther)
    Hello Reinhard,

    The script you modified on 16 Nov does not appear in the forum posting, so I cannot copy and paste it. However, if you can email it to me at **** I would very much appreciate it.

    Thanks and regards,

    Jeff
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 17, 2006 12:31 PM   in reply to (Lloyd_G_Guenther)
    Jeffrey,

    Click the "Show all messages" link towards the top of the thread and you'll see his post.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 9, 2007 5:26 PM   in reply to (Lloyd_G_Guenther)
    Reinhard, I love this Javascript for printing the file name as a footer on Acrobat documents; however, I DO need the whole path name as well as the file name to print on my documents...how do I fix this script so that this will happen? Thanks
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2007 11:39 AM   in reply to (Lloyd_G_Guenther)
    In the line:

    fd.value = util.printd(AcDateFormat, AcDate) + " (" + FileNM +")";

    replace FileNM with Path.

    Best regards, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 13, 2007 5:12 PM   in reply to (Lloyd_G_Guenther)
    This is fantastic...just what I was look for!...I just need to add a line of text stating the document will expire after so many days and the date and time to be ...mm/dd/yyyy and standard time not military time. What do I need to add and/or change to achieve this?
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2007 5:02 AM   in reply to (Lloyd_G_Guenther)
    1.)Dateformat
    Change the line:
    var AcDateFormat = "yyyy/mmm/dd HH:MM"
    to your needs, like:
    var AcDateFormat = "mm/dd/yyyy"

    For more Date formats have a look at the JavaScript help file:
    http://www.adobe.com/devnet/acrobat/pdfs/js_api_reference.pdf#page=716

    2.)document will expire
    A simple solution would be (see "answer #8"):
    - the first box (Date ...) uses the total width of the page. So it also useable if you want to have a selfmade footer note, something like "First Draft from ....". You have only to edit one box on one page, then it will be displayed on all pages.

    Another solution would be to set up an extra field (box) for that.

    HTH, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2007 6:11 AM   in reply to (Lloyd_G_Guenther)
    Reinhard,

    I have altered your code a bit for my specific needs...I need the month/day/time, then document name on the left hand side of the footer, the page of pages in the center...which you have...but then also...on the right hand side of the page, I need it jus plain text where I can type in a message....the code that you've written is a fantastic start...I jus need to figure out how to get that last part in there..and im fairly new to all this...plus..I don't know if removing stuff, I've messed up the other code...seems functional when I test it, but it maybe a bit sloppy after me messing with it!...how do I add that last piece of code? Thanks for your help!!

    app.addSubMenu({ cName: "Footer",cUser: "Test", cParent: "File", nPos: 20 });

    app.addMenuItem({ cName: "Set", cParent: "Footer", cExec: "SetFooter(9)"});

    app.addMenuItem({ cName: "-------------------------------", cParent: "Footer",cExec: "{}"});

    app.addMenuItem({ cName: "Remove", cParent: "Footer", cExec: "RemoveFooter(9)"});

    //Set/remove Footer
    function SetFooter(ARG)
    {
    var re = /.*\/|\.pdf$/ig;
    var FileNM = this.path.replace(re,"")+".pdf";
    var Path = this.path;
    var AcDate = new Date();
    var AcDateFormat = "mm/dd/yyyy HH:MM"
    var Box2Width = 50
    for (var p = 0; p < this.numPages; p++)
    {
    var aRect = this.getPageBox("Crop",p);
    var TotWidth = aRect[2] - aRect[0]
    if (ARG==9)
    { var fd = this.addField("xftDate", "text", p, [30,15, TotWidth-30-30,30]);
    fd.value = util.printd(AcDateFormat, AcDate) + " (" + FileNM +")";
    fd.textSize=6; fd.readonly = true;
    if (ARG==1){ fd.alignment="left" };
    if (ARG==2){ fd.alignment="center" };
    if (ARG==3){ fd.alignment="right" };
    }
    if (ARG==9)
    { var bStart=(TotWidth/2)-(Box2Width/2)
    var bEnd=((TotWidth/2)+(Box2Width/2))
    if (ARG==5){var bStart=(TotWidth-Box2Width-30); var bEnd=(TotWidth-30);}
    var fp = this.addField(String("xftPage"+p+1), "text", p, [bStart,30,bEnd,15]);
    fp.value = "Page: " + String(p+1)+ "/" + this.numPages;
    fp.textSize=6; fp.readonly = true;
    fp.alignment="center";
    }
    }
    }

    function RemoveFooter(ARG)
    {
    if (ARG==9) {var x = this.removeField("xftDate");}
    if (ARG==9)
    { for (var p = 0; p < this.numPages; p++)
    {var x = this.removeField(String("xftPage"+p+1)); }
    }
    }
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2007 6:36 AM   in reply to (Lloyd_G_Guenther)
    Hi

    I've been struggling to create an excel document which needs to go out with a header in the form of our company logo. As Excel has very limited layout capabilities, is it possible to use your script to add a header which just includes a (positioned) logo to an excel file being printed to PDF?

    Thanks
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2007 7:17 AM   in reply to (Lloyd_G_Guenther)
    Fantastic with the JS.

    Thanks to Reinhard and You all.

    I'm a 100% novice in this.

    But the

    var re = /.*\/|\.pdf$/ig;
    var FileNM = this.path.replace(re,"")+".pdf";
    var Path = this.path;

    doesn't seem to work by me. The filename is always "NaN.pdf".

    However - after a look in the js api documentation, I changed the 3 lines to just

    var FileNM =this.documentFileName

    It seems to work. Am I missing something?
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2007 12:21 PM   in reply to (Lloyd_G_Guenther)
    @esma
    You should open your own topic. It's a total different technic (watermarks or ..)

    @allan
    "Am I missing something?"
    No. I use AAv5. "documentFilename" was introduced in later versions. Also the regular expression I used I took only because I just worked with that and was to lazy to look for "stringMid, stringInStr ..." in a JS-handbook.

    Best regards, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2007 2:26 PM   in reply to (Lloyd_G_Guenther)
    @bjames

    A quick solution.
    Under: "if (ARG==3){ fd.alignment="right" };"
    Insert:
    var fr = this.addField("xftRem", "text", p, [30+TotWidth/2,15, TotWidth-30,30]);

    fr.textSize=6;fr.alignment="right";


    If you choose "Set Both" an extra field will be added to the right side of every page. This you can edit on one page for every page.

    If you want to remove it via Menuitem, then
    Under: "if (ARG<=3 || ARG==9) {var x = this.removeField("xftDate");}"
    Insert:
    if (ARG<=3 || ARG==9) {var x = this.removeField("xftRem");}

    HTH, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 15, 2007 1:29 PM   in reply to (Lloyd_G_Guenther)
    Reinhard,

    Thank you so much for your help. I just have one question. You have the code written above so that you may type the footnote or message on the bottom of the page in acrobat. I would like to put the text or message in the JavaScript. That way when you SETBOTH, it adds everything to the bottom and that's it. So my question is, how do I put that information in the code? and secondly where? Thanks again for your help.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 16, 2007 3:20 AM   in reply to (Lloyd_G_Guenther)
    Add:
    fr.value = "My Text";

    to:
    fr.textSize=6; fr.alignment="right";

    e.g
    fr.textSize=6; fr.alignment="right"; fr.value = "My Text";

    HTH, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2007 12:16 PM   in reply to (Lloyd_G_Guenther)
    I got the "Set/Remove Footer" thing to show up above print setup under the file drop-down, but when I click on any of the options it says, "an internal error occurred"

    Is this because I have Vista? any advice?

    thanks for your help
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 16, 2007 12:46 PM   in reply to (Lloyd_G_Guenther)
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 17, 2007 2:49 AM   in reply to (Lloyd_G_Guenther)
    "Is this because I have Vista? any advice?"

    I don't know. Which Acrobat version?
    You may test the pure script (without app.addMeuitem) in the JS-Console.

    best regards, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 17, 2007 6:16 AM   in reply to (Lloyd_G_Guenther)
    tried taking out app.addMeuitem and i'm still getting the same thing

    i'm using adobe 7.0

    thanks a lot for your help though
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 18, 2007 3:33 AM   in reply to (Lloyd_G_Guenther)
    I work with WinXP and furtheron with Acrobat v5. From the answer from @P.Allan I can see that it should work also with higher Acrobat versions.

    Perhaps someone else can confirm that ist works / works not with vista and with which Acrobat Version.

    Good luck, Reinhard
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 24, 2007 8:45 AM   in reply to (Lloyd_G_Guenther)
    This is great!

    Works with Acrobat 8.0

    those having trouble, make sure to save the .js file to the appropriate \program files\adobe\acrobat "X"\javascript folder.

    Questions:

    A. I am a novice at javascripting. what changes to the script need to be made to move this from footer to header?

    B. How to I make it so that this script is available to the Batch Processing in Acrobat?

    thanks in advance
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 23, 2007 7:31 AM   in reply to (Lloyd_G_Guenther)
    I have the same problem that Eli had with version 7.0. I've tried two versions of the JS above (PrintWithFooter.js) and (SetRemoveFooter.js), and I have the two sub-menus under the File menu, but "internal errors" every time I try to use them.

    Has anyone had any success with 7.0?

    Thanks,

    M
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 27, 2007 7:02 PM   in reply to (Lloyd_G_Guenther)
    Yes, I have used this script with professional 7.0 without problem. I did download from the site provided.
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 27, 2007 7:03 PM   in reply to (Lloyd_G_Guenther)
    Can any help me with changing the color of the font this script puts in the footer?

    It comes in black and the pdfs I am printing are already dark colors.

    best regards,
    DB
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 17, 2007 1:07 PM   in reply to (Lloyd_G_Guenther)
    This works great putting the filename to the Header was
    Just wondering if there is a way to change the font.
    fd.textsize changes the size of the font
    Why doesn't fd.textfont="Broadway" change the font.
    I Need it to printout a specila type of font is it possible
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 17, 2007 1:26 PM   in reply to (Lloyd_G_Guenther)
    You are creating a form field and can only use the fonts available to the form field. More information about the use of arbitrary fonts is contained in the Acrobat JavaScript Scripting Reference.
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 17, 2008 10:21 AM   in reply to (Lloyd_G_Guenther)
    How can I insert the filename into the header?
     
    |
    Mark as:
1 2 3 4 Previous Next
Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)