Rotate only landscape or portrait pages in the document and delete blank pages from PDF file

/* Rotate only landscape or portrait pages in the document */
// Modify nStart, nEnd and nRotate to change script logic
nStart = 0; // first page to rotate
nEnd = this.numPages - 1; // last page to rotate
nRotate = 0; // allowed rotations: 0, 90, 180, 270
bLanscape = true; // set to false to process only Portrait pages

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) { // portrait
                        if (!bLandscape) {
                                this.setPageRotations(i,i,nRotate)
                        }
                }
                else { // landscape
                        if (bLandscape) {
                                this.setPageRotations(i,i,nRotate)
                        }
                }
        }
}
catch(e)
{
        app.alert("Processing error: "+e)
}

// DELETE PAGES WITHOUT TEXT from the PDF document
// IMPORTANT: This script assumes that page is blank if it does not contain any "pdf words"
try {
        // save a copy of original document
        var newName = this.path;
        var filename = newName.replace(".pdf","_Original.pdf");
        this.saveAs(filename);
       
        for (var i = 0; i <  this.numPages; i++)
        {
            numWords = this.getPageNumWords(i);
            if (numWords == 0)
            {
            // this page has no text, delete it
            this.deletePages(i,i);
            }
        }
}
catch(e)
{
    app.alert(e);
}

VeryPDF JavaScript to PDF Embedder Command Line Home Page is:

https://www.verypdf.com/app/javascript-to-pdf-embedder-cmd/index.html

VeryPDF JavaScript to PDF Embedder Command Line Download URL is:

https://www.verypdf.com/dl2.php/addjs2pdf_win.zip

You can save above JS code to a text file, then you can run following command line to insert this JavaScript code into PDF file,

addjs2pdf.exe -runatopen js.txt in.pdf out.pdf

out.pdf file will contain the JavaScript code, when you open this PDF file in Adobe Acrobat software, above JavaScript code will be executed automatically.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!