Skip to main content
catherinew78546173
New Participant
May 17, 2018
Question

Use javascript to automate rotating a background image in Adobe Acrobat 2017?

  • May 17, 2018
  • 3 replies
  • 1606 views

Hi all.  I have Adobe Acrobat 2017 and I am new to running actions but trying to learn.  I have a pdf where the background image is sourced from a file and I need to rotate the image 270 degrees for the landscape pages only.  I'd like to use javascript to automate this process.  I found code to step through the document and find the landscape pages, but I can't figure out how to reference and rotate the background image.  Can someone help? 

/* Finds all landscape pages in current document */

var LandscapePageCount = 0;

{

    for (PageIndex = 0; PageIndex <= this.numPages - 1; PageIndex++)

    {

        // check if this page is landscape or portrait

        var aRect = this.getPageBox("Media",PageIndex);

        var PageWidth = aRect[2] - aRect[0];

        var PageHeight = aRect[1] - aRect[3];

       

        if (PageHeight < PageWidth)  // Landscape page found

        {

            LandscapePageCount++;

            // NEED HELP HERE

        }

    }   

    app.alert("Total number of landscape pages found: " + LandscapePageCount, 3);

}

This topic has been closed for replies.

3 replies

try67
Community Expert
May 18, 2018

JS can't do that. It can only rotate objects like form fields or comments or entire pages.

Bernd Alheit
Community Expert
May 18, 2018

How did you add the background image?

catherinew78546173
New Participant
May 18, 2018

I added it manually (Edit PDF -> Background -> Add, Source = a file on my computer) and I have added it by creating an Action that does the same thing.  I add the same footer on every page of the pdf, but the landscape ones need to be rotated 270 degrees and I can't figure out how to change the location of the background image for just those pages.

catherinew78546173
New Participant
May 18, 2018

For the landspace pages you can use a rotated image.


Bernd Alheit, great idea and thank you!  But how do I automate the process of selecting the rotated image for landscape pages and the non rotated image for portrait pages?

Kanikas
Community Manager
Community Manager
May 17, 2018