PDF-ShellTools > General

Script to add a blank page to pdf each n pages

<< < (2/3) > >>

RTT:
Something like this should do the job.


--- Code: ---//Full path to a 2 blank pages pdf
var BlankPagesPDFFilename = 'c:\\temp\\2BlankPages.pdf';

// Create a new merger object
var Merger = pdfe.CreateDocumentMerger();

var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var FullPathFilename = pdfe.SelectedFiles(i).Filename;
    var Filename = FullPathFilename.substring(FullPathFilename.lastIndexOf('\\') + 1);

    //insert each two pages rule
    var step = 2;

    pdfe.echo('Processing: ' + FullPathFilename);
    ProgressBar.position = i + 1;

    var pages = pdfe.SelectedFiles(i).Pages;

    Merger.MergeDocument(FullPathFilename, '1');

    for (j = 2; j <= pages.count; j += step) {

        Merger.MergeDocument(BlankPagesPDFFilename);

        var range = j.toString() + "-" + (j + step - 1).toString();
        Merger.MergeDocument(FullPathFilename, range);
    }

    //save the new file
    Merger.EndAndSaveTo("C:\\Temp\\2BlanksInserts_" + Filename);
    pdfe.echo('done');
}
pdfe.echo('finished');

--- End code ---

Don't forget to change the two hard coded file paths to your needs.

Ravi:
Hi,

1. How to use this Script in Adobe Acrobat 11 Pro?

2. I need to insert a blank page in between all pages in a pdf file, so what could be the Script?

Thanks,
Ravi

RTT:

--- Quote from: Ravi on February 06, 2015, 06:22:07 AM ---Hi,

1. How to use this Script in Adobe Acrobat 11 Pro?

2. I need to insert a blank page in between all pages in a pdf file, so what could be the Script?

Thanks,
Ravi

--- End quote ---

Using the PDF-ShellTools, this forum is all about, scripting environment and automating Acrobat Pro to do the inserts, something like this perhaps?

--- Code: ---var BlankPagePDF = "C:\\temp\\BlankPage.pdf";

var app = pdfe.CreateObject("AcroExch.App");
var baseDoc = pdfe.CreateObject("AcroExch.PDDoc");
var insertDoc = pdfe.CreateObject("AcroExch.PDDoc");
insertDoc.open(BlankPagePDF);

var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

var FullPathFilename;
var Filename;
var FileFolder;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    FullPathFilename = pdfe.SelectedFiles(i).Filename;
    Filename = FullPathFilename.substring(FullPathFilename.lastIndexOf('\\') + 1);
    FileFolder = FullPathFilename.substring(0, FullPathFilename.lastIndexOf('\\') + 1);
    pdfe.echo('Processing: ' + FullPathFilename);
    ProgressBar.position = i + 1;

    baseDoc.Open(FullPathFilename);
    n = baseDoc.GetNumPages();
    for (var j = isOdd(n) ? n : n - 1; j >= 0; j--) {
        baseDoc.InsertPages(j, insertDoc, 0, 1, 1);
    }

    baseDoc.Save(1, FileFolder + 'BlanksInserted_' + Filename);
    baseDoc.close();
}

insertDoc.close();
app.Exit();
pdfe.echo('finished');

function isOdd(n) {
    return n % 2
}

--- End code ---

irshadcyber:
HI... can i get a script / program only to add blank pages to all pdf files in a folder which has odd pages

RTT:

--- Quote from: irshadcyber on February 23, 2016, 03:37:50 AM ---HI... can i get a script / program only to add blank pages to all pdf files in a folder which has odd pages

--- End quote ---

Check if this one is what you need:

--- Code: ---// Create a new merger object
var Merger = pdfe.CreateDocumentMerger();

//set up the progress bar
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var File = pdfe.SelectedFiles(i);
    if (isOdd(File.NumPages)) {

        var Filename = File.Filename;

        pdfe.echo('Processing ' + Filename);
        ProgressBar.position = i + 1;

        //merge the full document
        Merger.MergeDocument(Filename);

        //add a blank page of the same size of the last one in the document   
        var LastPage = File.pages(File.pages.count - 1);
        Merger.MergeBlankPage(LastPage.width, LastPage.height);

        //save to a new file name
        var NoExtFilename = Filename.substring(0, Filename.lastIndexOf('.'));
        Merger.EndAndSaveTo(NoExtFilename + '_evenedup.pdf');

        pdfe.echo(' : done', 0, true);
    }
}
pdfe.echo('All done.');

/************************************************************/
function isOdd(n) {
    return n % 2
}

--- End code ---

If the reason you need this functionality is to merge all these documents later, or print in batch, and have each document starting in a new paper sheet, then you may also use the merge tool, that has this functionality of adding a blank page when merging documents with an odd number of pages.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Reply

Go to full version