PDF-ShellTools > General

Script to add a blank page to pdf each n pages

(1/3) > >>

Frank:
Hi,

We are using this wonderful tool everyday to merge the n pdf we receive in p pages groups (1pages.pdf, 2pages.pdf, ...)
Now what we would like to do is to use another scrip on every odd pages pdf to add a blank page every n pages...
Say we have a 3pages.pdf with 12 pages which is the merging of 4 pdf with 3 pages... (pdf1, pdf2, pdf3 and pdf 4 are 3 pages pdf and have been merged into a 12p pdf...
I would like to have a scrip that will add a blank page after every 3 pages 123 blank 456 blank 789 blank 10 11 12 blank and on and on...
In a perfect world, the script would read the number of pages between each blank insert on the file name (03pages.pdf would read 3, 11pages.pdf would read 11...)

My goal is to be able to print every pdf in duplex which I can do right only on even pages pdf or on odd pages pdf after have manualy added a blank pages after each sequence of n (n=odd number... )

I hope my poor english let me explain clearly what we are looking, and I hope too that what I want to do is possible.
I don't know a line about coding ! But more and more I think that I should dive in !!!

Anyway, thanks a lot for the feedback.

Frank

RTT:
Any inconvenient on "evening" these odd number of pages at the time you merge them with the merge script?

Something like this modified version of that script, that adds a separator blank page when the PDFs being merged have a odd number of pages.
Note:This script needs a blank page PDF at "c:\temp\blank.pdf".

--- Code: ---//Full path to a blank page pdf
var BlankPagePDFFilename='c:\\temp\\blank.pdf';

//sort selected PDFs by same number of page documents
var ByPageArray = {};
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var n = pdfe.SelectedFiles(i).Pages.Count;
    if (!ByPageArray[n]) {
        ByPageArray[n] = new Array();
    }
    ByPageArray[n].push(pdfe.SelectedFiles(i).Filename);
}

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

//Now merge all same number of pages documents
var ProgressBar = pdfe.ProgressBar;
for (var p in ByPageArray) {
    if (ByPageArray.hasOwnProperty(p)) {
        var a = ByPageArray[p];
        var addblank=isOdd(p);
        ProgressBar.max = a.length;
        for (var i = 0; i < a.length; i++) {
            var filename = a[i]
            pdfe.echo('Merging ' + filename);
            ProgressBar.position = i + 1;
            Merger.MergeDocument(filename);
            if (addblank) {
              Merger.MergeDocument(BlankPagePDFFilename);           
            }
        }
        Merger.EndAndSaveTo("C:\\Temp\\" + p + "pageDocs.pdf");
    }
}

function isOdd(n) {
    return n % 2
}

--- End code ---

Frank:
THANK YOU VERY MUCH !!!

It works like a charm.

First script + this one will save us tons of time !

Again, THANK YOU !!!

RTT:
Because it may also be useful, here is a script that fulfill your request to insert the blank pages to the already merged PDFs.
Only processes files that originate from the merge of even number of pages PDFs.


--- Code: ---//Full path to a blank page pdf
var BlankPagePDFFilename = 'c:\\temp\\Blank.pdf';
var getNumberRegEx = /^\d+/

// 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);
    var n = getNumberRegEx.exec(Filename);
    if (n && isOdd(Number(n[0]))) {
        var step = Number(n[0]);
        pdfe.echo('Processing ' + FullPathFilename);
        ProgressBar.position = i + 1;
        var pages = pdfe.SelectedFiles(i).Pages;
        for (j = 1; j <= pages.count; j += step) {
            var range = j.toString() + "-" + (j + step - 1).toString();
            Merger.MergeDocument(FullPathFilename, range);
            Merger.MergeDocument(BlankPagePDFFilename);
        }
        Merger.EndAndSaveTo("C:\\Temp\\evened-" + Filename);
    }
}

function isOdd(n) {
    return n % 2
}

--- End code ---

ken:
So I'd like to adapt the script to use the following way:
I have a large 1700 pages PDF from a customer which is a front and back for 850 names. I need to insert 2 blanks between the front and back so that it paginates and print correctly on our digital devices. If I have a PDF which is 2 blank pages, how specifically do I adapt the script so that it inserts every 2 pages within the 1700 page PDF?
page 1 (blank/blank) page 2, page 3 (blank/blank) page 4, page 5 (blank/blank) page 6, etc.

Navigation

[0] Message Index

[#] Next page

Go to full version