Solved

Javascript to add text annotations to all pages.

Posted on 2006-06-29
8
984 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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 

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 250 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

One of the questions I get asked again and again is how to validate a field value in an AcroForm with a custom validation script. Adobe provided a lot of infrastructure to do that with just a simple script. Let’s take a look at how to do that wit…
The Adobe PDF proprietary file format is recognized as secure and formulated. But these PDF files are also prone to corruption and any external threat like virus attacks, improper storage can hit PDF file integrity.This type of damages can make cruc…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

691 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