Using Javascript to Crop Pages in CropBox based on TrimBox

Hi
Is there a way to set crop sizes in mm into CropBox based on the sizes on TrimBox, with Acrobat Javascript?
(From the Crop Pages menu)
Scenario:
set TrimBox sizes (top, bottom, left, right) to CropBox (top, bottom, left, right)
Thanks

A batch process is good for running the final script. But for development, use the console window.  There's links to a video and an article in my signature block. 
Try running this code one line at a time in the console.
rectCrop = this.getPageBox("Crop", this.pageNum);
pgWidth = rectCrop[2];
pgHeight = rectCrop[1];
desired_width = 220 * 72/25.4;
desired_height = 297 * 72/25.4;
rectNewCrop = [ (pgWidth - desired_width)/2, (pgHeight + desired_height)/2, (pgWidth + desired_width)/2, (pgHeight - desired_height)/2];
setPageBoxes("Crop", this.pageNum,this.pageNum, rectNewCrop);
What results do you get?
Thom Parker
The source for PDF Scripting Info
pdfscripting.com
The Acrobat JavaScript Reference, Use it Early and Often
Then most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)

Similar Messages

  • How do I use Javascript to populate a text field based on a selection from a drop down box?

    Greetings,
    I have virtually no experience with JavaScript and I am trying to figure out how to add some basic automation features to an Adobe form.  I have a drop down box called "Hospital_Name" that will contain approximately 7 possible selections.  When the user makes a selection, I would like to have the text field (called "Hospital_Address") below the drop down box populate with the corresponding address for the selection.  I have the "Hospital_Address" text field configured for multiple lines and would like the address to have a line break between the street address and the city/state/zip.
    For example, if the user selected "Hospital 1", the text field would display:
    123 Main St
    Anytown, CA 12345
    Any help or examples you can provide would be greatly appreciated.

    You have the element names within the object within brackets.
    Make sure your brackets are properly placed and matched.
    // Place all pre-population data into a single data structure
    var Location = {
    "--Hospital--":{ line1: " ", line2: " " },
    "Bellevue Medical Center":{ line1: "2500 BMC Drive", line2: "Bellevue, NE 68123" },
    "CHI Bergan Mercy":{ line1: "7500 Mercy Road", line2: "Omaha, NE 68124" }, 
    "CHI Immanuel":{ line1: "6901 N. 72nd Street", line2: "Omaha, NE 68122" }, 
    "CHI Lakeside":{ line1: "16901 Lakeside Hills Court", line2: "Omaha, NE 68130" }, 
    "CHI Midlands":{ line1: "11111 S. 84th Street", line2: "Papillion, NE 68046" },
    "Creighton University Medical Center":{ line1: "601 N. 30th Street", line2: "Omaha, NE 68131" },
    "Nebraska Medical Center":{ line1: "4400 Emile Drive", line2: "Omaha, NE 68105" }
    // some debugging code to see location names;
    console.show();console.clear():
    for(I in Location) {
    console.println(I);
    // end debugging code;
    function SetFieldValues(Hospital_Name) {
        this.getField("AddLine1").value = Location[Hospital_Name].line1;
        this.getField("AddLine2").value = Location[Hospital_Name].line2;
    This is not a beginners task but requires a fair amount of knowledge about the structure of objects, defining strings, and structure of arrays.
    Are you sure you have all the field names correctly spelled and capitalized?
    Do you get any error in the JavaScript console?
    Just trying the line that defines the "Location", I get the following error:
    SyntaxError: invalid property id
    1:Console:Exec
    undefined
    All the form field in a PDF are processed by using JavaScript and any error in any script will stop JavaScript processing.
    It might help to have a link to the problem form.
    Make sure your brackets are properly placed and matched.
    // Place all pre-population data into a single data structure
    var Location = {
    "--Hospital--":{ line1: " ", line2: " " },
    "Bellevue Medical Center":{ line1: "2500 BMC Drive", line2: "Bellevue, NE 68123" },
    "CHI Bergan Mercy":{ line1: "7500 Mercy Road", line2: "Omaha, NE 68124" }, 
    "CHI Immanuel":{ line1: "6901 N. 72nd Street", line2: "Omaha, NE 68122" }, 
    "CHI Lakeside":{ line1: "16901 Lakeside Hills Court", line2: "Omaha, NE 68130" }, 
    "CHI Midlands":{ line1: "11111 S. 84th Street", line2: "Papillion, NE 68046" },
    "Creighton University Medical Center":{ line1: "601 N. 30th Street", line2: "Omaha, NE 68131" },
    "Nebraska Medical Center":{ line1: "4400 Emile Drive", line2: "Omaha, NE 68105" }
    function SetFieldValues(Hospital_Name) {
        this.getField("AddLine1").value = Location[Hospital_Name].line1;
        this.getField("AddLine2").value = Location[Hospital_Name].line2;

  • Using JavaScript to auto populate a field based on numeric value of a separate drop down field

    Hello, I am trying to set up a simple, I hope, javascript which will enable to me auto populate one field based on the numberic value of another field using Acrobat Pro XI.
    Essentially I have 2 drop down fields (we'll call them DD1 and DD2).
    DD1 is the sum of 8 preceding drop down values. That sum can be anywhere from 0 - 40. Whatever that sum falls within a range which identifies a rating. The ratings and ranges are below:
    0-8: Non-Performer  
    9-16: Low Performer  
    17-24: Performer  
    25-32: High Performer  
    33-40: Exceptional Performer
    DD2 is where the rating ("non-performer", "low performer", etc.) will be captured. Instead of requiring the user to look at DD1, determine the value, and then identify and input the rating manually, I would like DD2 to auto populate the rating based on the value (sum) in DD1.
    For example, if DD1 shows a value of 27 then DD2 would auto populate "High Performer". So how do I write this code or execute this? In excel I would use an if, then statement. Is there something similar in Acrobat Pro XI.
    Any help is greatly appreciated. Thank you in advance.

    If you use a text field, the custom calculation script could be:
    // Custom calculation script for text field
    (function () {
        var s = getField("DD1").valueAsString;
        // Blank this field if input is blank
        if (!s) {
            event.value = "";
            return;
        // Convert string to number
        var v = +s;
        // Set this field's value based on the input
        if (v <= 40 && v >= 33) {
            event.value = "Exceptional Performer";
            return;
        if (v < 33 && v >= 25) {
            event.value = "High Performer";
            return;
        if (v < 25 && v >= 17) {
            event.value = "Performer";
            return;
        if (v < 17 && v >= 9) {
            event.value = "Low Performer";
            return;
        if (v < 9 && v >= 0) {
            event.value = "Non-Performer";
            return;
        // If none of the above fit, blank this field
        event.value = "";

  • Using Javascript to show/unshow a field based on input in another field

    I want to display/not display a field in a JSP depending on what is selected in another field.
    I am using <div></div> element currently which is displayed/not displayed using a Javascript invoked by the first field.
    the problem with div is that I have to put it inside a <tr><td> otherwise it doesn't work. This makes the field look aloof from the rest of the page, and is also not aligned with the other fields.
    Is there anything other than <div> that can be used? or is there a way to correct the look of the field inside a div?
    Thanks

    You shouldn't have to put it inside a <tr><td> to get it to work. I've done what you are trying to do with <span></span> and it worked fine. I haven't tried it with a <div> but I can't image why that wouldn't work. Maybe you could post your code.

  • Error when using Javascript to scroll page in iFrame

    Hi again!
    I'm using a small Javascript to control the scrolling of a page loaded in an iFrame:
    <script type="text/javascript">
    var timer_id;
    function scroll_iframe(frm,inc,dir) {
      if (timer_id) clearTimeout(timer_id);
      if (window.frames[frm]) {
        if (dir == "v") frames[frm].scrollBy(0, inc);
        else window.frames[frm].scrollBy(inc, 0);
        timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
    function stopScroll() { if (timer_id) clearTimeout(timer_id); }
    </script>
    <a href="javascript:;" onmouseover="scroll_iframe('menu', -4, 'v'); return true" onmouseout="stopScroll(); return true">Up</a>
    <a href="javascript:;" onmouseover="scroll_iframe('menu', 4, 'v'); return true" onmouseout="stopScroll();  return true">Down</a>
    Running this results the error: "Adobe AIR runtime security violation for JavaScript code in the application security sandbox (window.setTimeOut)".
    I've read the page about "Avoiding security-related JavaScript errors" but I don't know how to implement the changes proposed in my script.
    Could anyone be so kind and help me with this?
    Thanks!

    Just wanted to say that I solved the problem...
    After long testing I came up with two functions (one for up and one for down) that have the following code at the end:
    timer_id = setTimeout(function(){scroll_iframe('up')}, 20); //move up
    timer_id = setTimeout(function(){scroll_iframe('down')}, 20); //move down
    I also stumbled on to another problem: if I set the scroll property from the iFrame to "no", so that the scroll bar is hidden, I'm not able to use the "scrollBy(x, y)" method.
    So what I did was use "frames['iframe'].document.getElementById('menu_content_div').style.top" to change the position of the content div inside the menu page. I had to put some restrictions so that the user isn't able to scroll the menu endlessly up or down, but then it worked like a charm!
    If anyone whants to do something similar, this is the code I ended up with:
    var timer_id;
    var position = 0;
         function scroll_iframe(direction) {
            if (timer_id) clearTimeout(timer_id);
            if (window.frames['iframe']) {
                if (direction == "up" && position<0) {
                    position += 8;
                    frames['iframe'].document.getElementById('menu_content_div').style.top = position+"px";
                    timer_id = setTimeout(function(){scroll_iframe('up')}, 40);
                menuContentDiv = frames['iframe'].document.getElementById('menu_content_div')
                heightPx = document.defaultView.getComputedStyle(menuContentDiv,null).getPropertyValue('height');
                heightValue = heightPx.slice(0,(heightPx.length-2)); //removes the "px at the end of heightPx
                height = (heightValue-387)-2*(heightValue-387); //sets how much the menu can scroll up until it gets to its end - depends on the iframe height
                if (dir == "down" && position>height) {
                    position -= 8;
                    frames['iframe'].document.getElementById('menu_content_div').style.top = position+"px";
                    timer_id = setTimeout(function(){scroll_iframe('down')}, 40);
         function stopScroll() {
         if (timer_id) clearTimeout(timer_id);
    Scroll down: onMouseDown="scroll_iframe('down'); return true" onMouseUp="stopScroll(); return true"
    Scroll up: onMouseDown="scroll_iframe('up'); return true" onMouseUp="stopScroll(); return true"

  • How to crop pages using Adobe LiveCycle ES2 PDF Generator and Acrobat 9.2 Pro Extended

    Hi all,
    I'm evaluating the possibilities of Adobe LiveCycle ES2.0 PDF Generator in order to convert on the fly (programmatically) MS Office Documents and Visio drawings into PDF files.
    I'm able to trigger this process using the Webservices API (from within C#). However when generating the PDF files in this way, each and every PDF file has a lot of white margins around it as it is generated as an 8x11 inch page.
    I have been looking in ways to crop these white margins from around the information, so that the PDF content is only showing the actual content (in order to be used as an image).
    I found a way of doing this manually by opening the generated PDF file of LiveCycle in Acrobat 9.2 Pro Extended and using the Document > Crop Pages... option.
    So my question is: Can this be done programmatically using Adobe LiveCycle ES (and/or API functions of the Acrobat tool).
    The envisioned solution would run on a server (without interaction/monitoring requirements by a human).
    Any input about this is highly appreciated.
    Kind Regards,
    Raf
    Raf Snijders

    Hi all,
    I'm evaluating the possibilities of Adobe LiveCycle ES2.0 PDF Generator in order to convert on the fly (programmatically) MS Office Documents and Visio drawings into PDF files.
    I'm able to trigger this process using the Webservices API (from within C#). However when generating the PDF files in this way, each and every PDF file has a lot of white margins around it as it is generated as an 8x11 inch page.
    I have been looking in ways to crop these white margins from around the information, so that the PDF content is only showing the actual content (in order to be used as an image).
    I found a way of doing this manually by opening the generated PDF file of LiveCycle in Acrobat 9.2 Pro Extended and using the Document > Crop Pages... option.
    So my question is: Can this be done programmatically using Adobe LiveCycle ES (and/or API functions of the Acrobat tool).
    The envisioned solution would run on a server (without interaction/monitoring requirements by a human).
    Any input about this is highly appreciated.
    Kind Regards,
    Raf
    Raf Snijders

  • Crop page based on trim box not working

    Hi everyone,
    I have a 1-page file created in Illustrator. I exported this file to pdf and have applied trim marks. Back in Acrobat Pro, I go into the crop pages dialogue box and choose "trimbox". When I do this, 11.642 mm is automatically inserted into the margin fields for all 4 sides. When I click OK, I expected the file to be trimmed to A4 (210 x 297) but no change occurred in the file.
    I wondered if anyone knows why this has happened or what I'm doing wrong?
    Appreciate any help.

    you need to tell Acrobat the measurement:
    click on trim: copy the measurement in the margin control
    click crop, check the constrain proportions box and paste trim measurement
    click ok
    G

  • Allowing only pdf files in document library using Javascript

    HI,
    I have a document library in sharepoint 2013, where i want only pdf files to get uploaded in it. I have created event receiver for the same and it is working fine. but i want to restrict the files using javascript on
    the page itself, since, In event receiver, after the file is getting uploaded, it is checking and throwing error. So, is there any way to check for the file type before uploading the file and show error message if wrong file is uploaded?
    Harikrishna Baskaran

    Bind event to the upload button and add jquery to validate the file extension. Refer to the following posts for more information
    http://stackoverflow.com/questions/13124950/change-onclick-event-input-type-button-in-ie-8-9-ff-with-jquery-won%C2%B4t-wo
    http://stackoverflow.com/questions/4234589/validation-of-file-extension-before-uploading-file
    --Cheers

  • Using javascript to populate one menu based on the choice in another menu

    I have several menus which are dynamically populated (with PHP and MYSQL). The information is category based. How do I dynamically populate the second menu based on the choice the user makes in the first menu (without having to submit and refresh the page-- i.e. I need to use javascript instead of the server-side PHP).
    Example:
    Main Categories: 1) Numbers     2) Letters
    Sub Categories:        1                      a
                                   2                      b 
                                   3                      c
                                  etc.                  etc.
    the first menu contains the two main categories. I want the second list to be populated with only the sub categories of the main category the user chooses in the first menu (i.e. 1,2,3 etc. if he chose the main category 'Numbers' and a,b,c, etc. if he chose the main category 'Letters')
    Is there an easy way to do this in Dreamweaver?
    Thanks,
    YWSW

    How many items do you have in each dropdown? If it's a small number, you can download all of the options for the second dropdown and use client side javascript to filter based on the choice of the first dropdown. If the number is large, you'll need to use AJAX to dynamically pull the related items from the database.
    Search the web for "dependent dropdown" or "cascading dropdown" for some technical details.

  • How to Redirect to another page Using JavaScript in ADF Faces?

    Hi Guys,
    I have a UI user case that has a af:menu which contains mutiple af:goMenuItem. When user click on the menu, the menu slides down and shows up the af:goMenuItem. As we know, you could define the page destinations in af:goMenuItem to go to another page when user clicked, but af:menu itself cannot be redirected to another page. Well, the user case wants the menu itself could be redirected if user click on it.
    So I am thinking using JavaScript to do this: when the af:menu gets clicked, redirect to another page. BUT, I looked over the ADF Faces Javascript API and was not able to find that piece of code to do this. Any help???
    Another work around for the user case scenario is to use HTML marks + CSS/JavaScript instead of af:menu and af:goMenuItem but this changes the scope of technology although it's not hard to do
    Any other idea to accomplish the user case other than what I could think of ?
    Thanks Guys!
    Jay

    Hi,
    1 - you can have a hidden command item to do the navigation based on a control flow case. In this case, you access the command component from JavaScript create a new ActionEvent and queue it
    2 - JavaScript can use an af:serverListener to call into a server side managed bean method to perform the navigation
    there is no JavaScript API for navigation in ADF Faces because navigation in JavaServer Faces is an event driven framework and we don't support developers fighting the framework.
    Frank

  • How to show modal window without popup in a web page using javascript

    Hi,
    How to show modal window without popup in a web page using javascript, means when the modalwindow is opened it should not ask for popup blocker alert......
    pls help me.....

    Thanx for ur reply,
    Actually the senario is when i click on a button, another jsp page should be displayed in a modal window without popup, but the functions alert() and confirm() will not accept the url path of the another jsp page...

  • How to get page number from the PDF using Javascript

    Hi,
    We are having list of Single page PDF. The pdf are named in the order,
    ISBN_Author_01.PDF  (with real page number as i)
    ISBN_Author_02.PDF  (with real page number as ii)
    ISBN_Author_03.PDF  (with real page number as iii)
    ISBN_Author_04.PDF  (with real page number as 1)
    ISBN_Author_05.PDF  (with real page number as 2)
    ISBN_Author_06.PDF  (with real page number as 3)
    ISBN_Author_nn.PDF  (with real page number as 500)
    Here each pdf has a page number and in sequential order.
    The task is to check whether all the pdfs are in sequential order (i.e i, ii, iii, 1, 2, 3). If any page is missing, the script should throw an error report.
    To do this task, I am writing a Javascript to get the real page number from the PDF.
    Can anybody help me how to get the page number from the PDF using Javascript.
    Thanks,
    Gopal

    The "real" page number within a PDF is the count of the physical page starting at 0, zero.
    pageNum numPages
    The number printed on each page is the page label.
    setPageLabels  getPageLabel
    You will have to open each PDF and your script would need to know the page label for that file. I would expect you would need to build a 2 dimensional  array of the file names and the page label for the page within that array.

  • I would like to know why when i make a web page and test in my local browser it works fine then when i tranfer to my server i does not work fine example i used javascript to put a prompt bar on a page and it worked fine local but on server not working

    how come when i make a web site and i test it in my local server it works fine when i tranfer to server certain things do not work example i used javascript to put in a prompt bar for a newsletter page at the server it did not work but at local it did also it works at MOZZILLA but not internet explorer i also have cs4 was wondering if there is a way to test a page in dreamweaver and then transfer   THANK YOU X-FACTOR-MEDIA

    In future, please try to make the subject line of your posts shorter. In this case the following would have been sufficient: "JavaScript works locally, but not on remote server".
    Short, but meaningful subject lines make it easier for others to identify what your question is about, and often bring faster help.

  • How to change the print page setup in IE using javascript

    dear all,
    I want to take print out envelope paper size, so i want to chnage the page setup in IE
    i want to change the print page setup in IE using javascript

    I think, you can do this using CSS.
    http://support.sas.com/rnd/base/ods/templateFAQ/Template_csstyle.html

  • How to seperate current page fields in a pdf form using javascript

    Hi,
    Is that possible to seperate current page fields(textbox, Chesckbox) in a pdf form using javascript.
    I have coding to get all the fields in a pdf form. But i want to take CURRENT PAGE alone.
    Please help me out.
    Thanks and regards,
    Christy

    Hi try67,
    Thanks for your support.
    I got the result.
    Thanks and Regards,
    Christy

Maybe you are looking for