Link to home
Create AccountLog in
Avatar of -Tikigod-
-Tikigod-Flag for United States of America

asked on

Is there a way to Delete/Remove only horizontal/landscape oriented pages in a PDF document?

I have a single pdf document containing both landscape and portrait oriented pdf pages.  I want to run a batch process to remove only the horizontal oriented pages.  Is there a .js script I can place in adobe or batch process I can run to do this?
ASKER CERTIFIED SOLUTION
Avatar of krishna kishore mellacheruvu venkata
krishna kishore mellacheruvu venkata
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of -Tikigod-

ASKER

That site helped.  I threw together the following script.  It still has some errors but, it accomplishes the task I need by finding and removing the horizontal pages.  

Issues with code below:
- First and Last pages that are horizontal don't get deleted.
- "Processing error: InvalidArgsError: Invalid arguments." occurs
- I'd like to include a script that automatically renumbers pages from page 1 to the last page.

app.addMenuItem({ cName: "Delete Horizontal Pages", cParent: "Document", cExec: "DelHorizontalPages();", cEnable: "event.rc = (event.target != null);", nPos: 0
});

/* Delete only landscape pages in the document */

// Modify nStart, nEnd to change script logic

function DelHorizontalPages()
{
nStart = 0; // first page to scan for landscape pages
nEnd = this.numPages - 1; // last page to scan for landscape

try {

    for (var i = nStart; i <= nEnd; i++)
    {
       // check if this page is landscape or portrait
       var aRect = this.getPageBox("Media",i);
       var Width = aRect[2] - aRect[0];
       var Height = aRect[1] - aRect[3];
       if (Height < Width) { // landscape
	
	     this.deletePages(i,i);
		 
		}
	}
       
} 
catch(e)
{
app.alert("Processing error: "+e)
}
}// JavaScript Document

Open in new window