?
Solved

Javascript to add text annotations to all pages.

Posted on 2006-06-29
8
Medium Priority
?
1,030 Views
Last Modified: 2008-02-26
I Need help to write a JavaScript program that asks for a log number and then creates the annotations to be put on all subsequent pages all in the same location.
0
Comment
Question by:andywheaton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17018628
I am swamped with work right now. How urgent is this? I can provide a solution over the weekend.
0
 

Author Comment

by:andywheaton
ID: 17018728
I originally asked this question in March to no avail. I ended up quitting EE over the lack of response to my only question I had posed. I ended up rejoining after it solved a different problem for me. So I thought I would repose the question. Lo and behold you answered. So no there is no big hurry on this. Again thanks for your help.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17031433
OK, I'm back. I see that you posted your first question in a different TA - I don't hang out there ;)

Acrobat allows you to create JavaScript files that get executed when you start the application. We will make use of that feature with the following script - to add a menu item to Acrobat's "Document" menu. Create a new text file (use Notepad for that) in c:\Program Files\Acrobat 7.0\Acrobat\JavaScripts with the name "AddLogNumber.js" with the following content:

var dialog1 = {
    initialize: function (dialog) {
        this.logNumber = -1;
    },
    commit:function (dialog) { // called when OK pressed
        var results = dialog.store();
        this.logNumber = results["fnum"];
    },
    description:
    {
        name: "Log Number (2)", // dialog title
        align_children: "align_left",
        elements:
        [
                 {
                    type: "view",
                    align_children: "align_left",
                alignment: "align_fill",
                    elements:
                    [
                    {
                        type: "static_text",
                        name: "Log Number: "
                    },
                    {
                        item_id: "fnum",
                        type: "edit_text",
                  width: 80,
                    },
                   
                    {
                        type: "ok_cancel",
                        ok_name: "Ok",
                        cancel_name: "Cancel"
                     }
                     ]
                 }
          ]
   }
};

function addTextField(logNumber)
{
    // add the text field to every page
    for (var i=0; i<this.numPages; i++)
    {
        var annot = this.addAnnot(
        {
            page: i,
            type: "FreeText",
            rect: [36, 36, 108, 72],    // location and size of text field in points
            contents: logNumber,
        });
    }
}


function AddTextField()
{
    // create the user interface
    if (app.execDialog(dialog1) == "ok")
    {
       addTextField(dialog1.logNumber);
    }
}


// add the menu item
app.addMenuItem({
     cName: "JSAddTextField",
     cUser: "Add Text Field",
     cParent: "Document",
     cExec: "AddTextField()",
     cEnable: "event.rc = (event.target != null);",
     nPos: 0
});

// end of script

You can adjust the size and location of the text field by changing the "rect" data. The information is stored in points (72 points are one inch), and given in two coordinates: lower left and upper right corner.

Let me know if you run into any problems.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:andywheaton
ID: 17044788
I have tried the above twice. When I open a document indeed there is a new menu item under Document named "Add Text Field". When I select it I get a dialog box asking me for The "Log Number". But when I type in something and hit enter nothing appears to happen. Any Ideas?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17044832
Open the JavaScript console (Ctrl-J) and see any errors are reported.
0
 

Author Comment

by:andywheaton
ID: 17044874
I did not see any errors. This is what was there.

Acrobat Database Connectivity Built-in Functions Version 7.0
Acrobat EScript Built-in Functions Version 7.0
Acrobat Annotations / Collaboration Built-in Functions Version 7.0
Acrobat Annotations / Collaboration Built-in Wizard Functions Version 7.0
Acrobat Multimedia Version 7.0
Acrobat SOAP 7.0
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 1000 total points
ID: 17045598
That's odd... I developed the script on a Mac with Acrobat 7 Pro - and it worked. I just tried it on a Windows machine with the same version of Acrobat, and it fails here too.

I changed the script a little. Try this (it works on my Windows machine):

var dialog1 = {
    initialize: function (dialog) {
        this.logNumber = -1;
    },
    commit:function (dialog) { // called when OK pressed
        var results = dialog.store();
        this.logNumber = results["fnum"];
    },
    description:
    {
        name: "Log Number", // dialog title
        align_children: "align_left",
        elements:
        [
                 {
                    type: "view",
                    align_children: "align_left",
              alignment: "align_fill",
                    elements:
                    [
                    {
                        type: "static_text",
                        name: "Log Number: "
                    },
                    {
                        item_id: "fnum",
                        type: "edit_text",
               width: 80,
                    },
                   
                    {
                        type: "ok_cancel",
                        ok_name: "Ok",
                        cancel_name: "Cancel"
                     }
                     ]
                 }
          ]
   }
};

function processPages(doc, logNumber)
{
    // add the text field to every page
    var n = doc.numPages;
    for (var i=0; i<n; i++)
    {
        var annot = doc.addAnnot(
        {
            page: i,
            type: "FreeText",
            rect: [36, 36, 108, 72],    // location and size of text field in points
            contents: logNumber,
        });
    }
}


function AddTextField(doc)
{
    // create the user interface
    if (app.execDialog(dialog1) == "ok")
    {
       processPages(doc, dialog1.logNumber);
    }
}


// add the menu item
app.addMenuItem({
     cName: "JSAddTextField",
     cUser: "Add Text Field",
     cParent: "Document",
     cExec: "AddTextField(this)",
     cEnable: "event.rc = (event.target != null);",
     nPos: 0
});

// end of script
0
 

Author Comment

by:andywheaton
ID: 17045668
WOW that is great and it will save me a lot of work. Thanks for your help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
*Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Suggested Courses

777 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