1 2 3 Previous Next 160 Replies Latest reply on Dec 29, 2015 10:26 AM by gkaiseril

    Print File Name with pdf Document

    Level 1
      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?
        • 1. Re: Print File Name with pdf Document
          Level 1
          I have exactly the same question; it's unimaginable that this can't be done.
          • 2. Re: Print File Name with pdf Document
            Level 1
            you can do it with a JavaScript.
            • 3. Re: Print File Name with pdf Document
              Level 1
              Add some JavaScript to your document as a "Will print" event.

              Details in the Acrobat JavaScript Guide.

              Leonard
              • 4. Re: Print File Name with pdf Document
                Level 1
                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.
                • 5. Re: Print File Name with pdf Document
                  Level 1
                  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
                  • 6. Re: Print File Name with pdf Document
                    ReinhardF Level 3
                    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));

                    } }

                    }
                    • 7. Re: Print File Name with pdf Document
                      Level 1
                      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
                      • 8. Re: Print File Name with pdf Document
                        ReinhardF Level 3
                        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)); }

                        } }
                        • 9. Re: Print File Name with pdf Document
                          ReinhardF Level 3
                          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)); }

                          } }
                          • 10. Re: Print File Name with pdf Document
                            Level 1
                            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
                            • 11. Re: Print File Name with pdf Document
                              ReinhardF Level 3
                              I've edited above script and now it should work.

                              br, Reinhard
                              • 12. Re: Print File Name with pdf Document
                                Level 1
                                Thanks. Can you post it?

                                Regards

                                Jeff
                                • 13. Re: Print File Name with pdf Document
                                  ReinhardF Level 3
                                  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
                                  • 14. Re: Print File Name with pdf Document
                                    ReinhardF Level 3
                                    Just remembered to some Webspace I have. You can download from:

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

                                    HTH Reinhard
                                    • 15. Re: Print File Name with pdf Document
                                      Level 1
                                      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
                                      • 16. Re: Print File Name with pdf Document
                                        ~graffiti Adobe Community Professional & MVP
                                        Jeffrey,

                                        Click the "Show all messages" link towards the top of the thread and you'll see his post.
                                        • 17. Re: Print File Name with pdf Document
                                          Level 1
                                          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
                                          • 18. Re: Print File Name with pdf Document
                                            ReinhardF Level 3
                                            In the line:

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

                                            replace FileNM with Path.

                                            Best regards, Reinhard
                                            • 19. Re: Print File Name with pdf Document
                                              Level 1
                                              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?
                                              • 20. Re: Print File Name with pdf Document
                                                ReinhardF Level 3
                                                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
                                                • 21. Re: Print File Name with pdf Document
                                                  Level 1
                                                  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)); }
                                                  }
                                                  }
                                                  • 22. Re: Print File Name with pdf Document
                                                    Level 1
                                                    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
                                                    • 23. Re: Print File Name with pdf Document
                                                      P. Allan Level 1
                                                      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?
                                                      • 24. Re: Print File Name with pdf Document
                                                        ReinhardF Level 3
                                                        @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
                                                        • 25. Re: Print File Name with pdf Document
                                                          ReinhardF Level 3
                                                          @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
                                                          • 26. Re: Print File Name with pdf Document
                                                            Level 1
                                                            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.
                                                            • 27. Re: Print File Name with pdf Document
                                                              ReinhardF Level 3
                                                              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
                                                              • 28. Re: Print File Name with pdf Document
                                                                Level 1
                                                                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
                                                                • 30. Re: Print File Name with pdf Document
                                                                  ReinhardF Level 3
                                                                  "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
                                                                  • 31. Re: Print File Name with pdf Document
                                                                    Level 1
                                                                    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
                                                                    • 32. Re: Print File Name with pdf Document
                                                                      ReinhardF Level 3
                                                                      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
                                                                      • 33. Re: Print File Name with pdf Document
                                                                        Level 1
                                                                        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
                                                                        • 34. Re: Print File Name with pdf Document
                                                                          Level 1
                                                                          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
                                                                          • 35. Re: Print File Name with pdf Document
                                                                            Level 1
                                                                            Yes, I have used this script with professional 7.0 without problem. I did download from the site provided.
                                                                            • 36. Re: Print File Name with pdf Document
                                                                              Level 1
                                                                              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
                                                                              • 37. Re: Print File Name with pdf Document
                                                                                Level 1
                                                                                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
                                                                                • 38. Re: Print File Name with pdf Document
                                                                                  gkaiseril MVP & Adobe Community Professional
                                                                                  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.
                                                                                  • 39. Re: Print File Name with pdf Document
                                                                                    Level 1
                                                                                    How can I insert the filename into the header?
                                                                                    1 2 3 Previous Next