Using the cropping idea, the next script creates a new PDF with all the A3 pages split into two A4. The split is done by adjusting the media and crop boxes and duplication of the page reference.
var Merger = pdfe.CreateDocumentMerger();
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
ProgressBar.position = i + 1;
try {
var File = pdfe.SelectedFiles(i),
Filename = File.Filename,
Pages = File.Pages;
var Path = Filename.substr(0, Filename.lastIndexOf('\\') + 1),
Name = Filename.substring(Path.length, Filename.lastIndexOf('.'));
pdfe.echo('>' + Filename);
for (var PageIndex = 0; PageIndex < Pages.Count; PageIndex++) {
var Page = Pages(PageIndex);
if (Page) {
var w = Math.min(Page.Width, Page.Height);
var h = Math.max(Page.Width, Page.Height);
//A3=297x420
if (Math.abs(w - 297) < 15 && Math.abs(h - 420) < 15) {
pdfe.echo(' Splitting page ' + (PageIndex + 1).toString());
var box = Page.CropBox;
if (box.Right - box.Left < box.Top - box.Bottom) {
if (Page.Rotation == 90) {
var oriBoxTop = box.Top;
box.Top = box.Top + (box.Bottom - box.Top) / 2;
Page.MediaBox = box;
Page.CropBox = box;
Merger.MergePage(Page);
box.Bottom = box.Top;
box.Top = oriBoxTop;
Page.MediaBox = box;
Page.CropBox = box;
} else {
var oriBoxBottom = box.Bottom;
box.Bottom = box.Top + (box.Bottom - box.Top) / 2;
Page.MediaBox = box;
Page.CropBox = box;
Merger.MergePage(Page);
box.Top = box.Bottom;
box.Bottom = oriBoxBottom;
Page.MediaBox = box;
Page.CropBox = box;
}
} else {
if (Page.Rotation == 270) {
var oriBoxLeft = box.Left;
box.Left = box.Left + (box.Right - box.Left) / 2;
Page.MediaBox = box;
Page.CropBox = box;
Merger.MergePage(Page);
box.Right = box.Left;
box.Left = oriBoxLeft;
Page.MediaBox = box;
Page.CropBox = box;
} else {
var oriBoxRight = box.Right;
box.Right = box.Left + (box.Right - box.Left) / 2;
Page.MediaBox = box;
Page.CropBox = box;
Merger.MergePage(Page);
box.left = box.right;
box.right = oriBoxRight;
Page.MediaBox = box;
Page.CropBox = box;
}
}
}
Merger.MergePage(Page);
}
}
var NewFilename = Path + Name + '_A3To2A4.pdf';
if (Merger.EndAndSaveTo(NewFilename)) {
pdfe.echo(' Saving to: ' + NewFilename + ' [OK]', 0)
} else {
pdfe.echo(' Saving to: ' + NewFilename + ' [Failed]', 0xFF0000);
}
} catch (e) {
pdfe.echo(Filename + ' :' + e.message, 0xFF0000);
}
}
pdfe.echo("Done");