JavaScript for Acrobat

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

JavaScript for Acrobat

One of the easiest and most powerful ways to customize PDF files is by using JavaScript. Based on JavaScript version 1.5 of ISO-16262 (formerly known as ECMAScript), JavaScript in Adobe Acrobat software implements objects, methods, and properties that enable you to manipulate PDF files, produce database-driven PDF files, modify the appearance of PDF files, and much more. You can tie Acrobat JavaScript code to a specific PDF document, a page, field, or button within that document, or a field or button within the PDF file, and even to a user action.

JavaScript is particularly useful for XML forms. JavaScript enables automated forms handling, Web and database communication, commenting, and user-interface capabilities. PDF files created with Acrobat and Adobe LiveCycle tools allow data to be extracted as XML into custom schemas. Applications written in Java and other languages easily integrate Acrobat with Web services using Simple Object Access Protocol (SOAP).

Beginning with Acrobat 7, there have been extensive improvements to the JavaScript functionality. There is now support for multimedia, improved printing control, controlling layers, 3D support, and more.

JavaScript: set max width

    <script type="text/javascript">
    window.onload = resize;
    window.onresize = resize;

    function resize() {
    var max_width = 800

    /* - FireFox does not support object reference, must use getElementby */
    var doc_body = document.getElementsByTagName('body')[0];
    var doc_container = document.getElementById('container');


    /* - set the max width */
    /* - FireFox must have unit (px) */
    if (doc_body.clientWidth < max_width)
    doc_container.style.width = doc_body.clientWidth + 'px';
    else
    doc_container.style.width = max_width + 'px';

    }
    </script>

JavaScript: set element width

    <script type="text/javascript">
    window.onload = resize;
    window.onresize = resize;

    function resize() {
    /* - FireFox does not support object reference, must use getElementby */
    var object_a= document.getElementById('a');
    var object_b = document.getElementById('b');

    /* - hidden the element DIV comments, otherwise the page will resize forever even the uesers would not notice */
    doc_comments.style.visibility = 'hidden';
/* - reduce the size first, otherwise the object_b would not resize correctly because they are under the same table */
    doc_comments.style.width = '0px';


    ..... other resize statements ......

    doc_comments.style.width = (object_b.offsetWidth - 10) + 'px';
    doc_comments.style.visibility = 'visible';
    }
    </script>