RTTSoftware Support Forum

PDF-ShellTools => Ideas/Suggestions => Topic started by: nightslayer23 on March 13, 2020, 02:20:55 AM

Title: More dynamic merge tool
Post by: nightslayer23 on March 13, 2020, 02:20:55 AM
I have spoken on here a little bit before about a solution for variable data merging and you pointed me to use the "duplicate" button in the merge window. that helped! but is quite a manual process when you need to duplicate one artwork 40 times and then the next one 20 times etc...

If the merge tool had an extra column whereby you could input a number of copies for that artwork in the merge, it would be huge!

Title: Re: More dynamic merge tool
Post by: RTT on March 15, 2020, 03:58:10 PM
That's a good idea! Keep the current duplicate entry functionality, for when there is the need to specify a different page selector, and add a number of copies for each of the entries, for when we just want to repeat the specific entry multiple times.
Now in the TODO list.
Title: Re: More dynamic merge tool
Post by: nightslayer23 on March 30, 2020, 04:23:38 AM
 ;D awesome! let me know if you get to this!

no other program out there that can do this.
Title: Re: More dynamic merge tool
Post by: nightslayer23 on May 14, 2020, 01:03:01 AM
Hi again! will this be in he next update do you think?
Title: Re: More dynamic merge tool
Post by: RTT on May 14, 2020, 08:32:35 PM
Yes. It's already implemented and working around here.
Title: Re: More dynamic merge tool
Post by: nightslayer23 on May 15, 2020, 06:31:57 AM
Yes. It's already implemented and working around here.

oh awesome! can't wait til its released   ;D
Title: Re: More dynamic merge tool
Post by: nightslayer23 on May 22, 2020, 02:40:54 AM
do we have a time frame for when the latest version will be released?
Title: Re: More dynamic merge tool
Post by: RTT on May 23, 2020, 01:06:02 AM
I hope it will be soon, but don't know yet.
Meanwhile, a script can be used to provide this "copies" functionality. How exactly will you be using it?
Title: Re: More dynamic merge tool
Post by: nightslayer23 on June 26, 2020, 01:49:26 AM
Same as explained above, when you go to combine, window pops up that allows you to add number of copies per file. variable data and variable copies for each
Title: Re: More dynamic merge tool
Post by: RTT on June 30, 2020, 01:43:22 AM
Try this script:
Code: [Select]
var options = {
    params: []
};

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var Filename = pdfe.SelectedFiles(i).Filename;
    var fileOpt = {
        type: 'edit',
        name: i,
        label: 'Copies of ' + Filename,
        def: 1
    };
    options.params.push(fileOpt);
}

try {
    options = JSON.parse(pdfe.DialogBox(JSON.stringify(options)));
    if (options.Canceled) {
        pdfe.echo('canceled');
        pdfe.quit();
    }
} catch (err) {
    pdfe.quit();
}

var Merger = pdfe.CreateDocumentMerger();
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var File = pdfe.SelectedFiles(i);
    var Filename = File.Filename;
    pdfe.echo(Filename);
    ProgressBar.position = i + 1;
    var copies = parseInt(options[i]) || 1;
    for (var n = 0; n < copies; n++)
    Merger.MergeDocument(Filename);
}

var dialog = pdfe.SaveDialog;
dialog.DefaultExt = '.pdf';
dialog.filter = 'PDF documents (*.pdf)|*.pdf';
dialog.Options = '[ofOverwritePrompt]';
dialog.Filename = Filename.substring(0, Filename.lastIndexOf('.')) + '_merged.pdf';
if (dialog.execute) {
    Merger.EndAndSaveTo(dialog.Filename);
    pdfe.echo('Done.');
}
Title: Re: More dynamic merge tool
Post by: nightslayer23 on July 27, 2020, 09:02:53 AM
this didn't quite work.. :-\

it just combined and prompted for a directory to save to
Title: Re: More dynamic merge tool
Post by: RTT on July 28, 2020, 01:22:34 AM
You probably have set the "Hide output window" option for the script? That will suppress the dialog that is asking for the number of copies.
Title: Re: More dynamic merge tool
Post by: nightslayer23 on August 07, 2020, 07:58:46 AM
nope, it shows, just doesn't give me an option to enter an amount of copies.
Title: Re: More dynamic merge tool
Post by: nightslayer23 on August 11, 2020, 02:37:56 AM
note: it works in the debugger! when you go to settings, but it doesn't work from the context menu. cheers
Title: Re: More dynamic merge tool
Post by: RTT on August 12, 2020, 01:12:06 AM
No idea then. It's working fine here in various Windows versions.
You can run the script from the script editor/debugger, when launching from the shell context menu, by pressing the CTRL key when invoking the script.
Title: Re: More dynamic merge tool
Post by: nightslayer23 on November 05, 2020, 02:58:18 AM
No idea then. It's working fine here in various Windows versions.
You can run the script from the script editor/debugger, when launching from the shell context menu, by pressing the CTRL key when invoking the script.

yes I've been using it this way - only way it works to bring up the query dialog parameter box. if not in debugger mode, it skips the dialog box and goes straight to the save as output window.
Title: Re: More dynamic merge tool
Post by: nightslayer23 on November 06, 2020, 12:39:02 AM
actually after posting here I came up with the thought that if maybe I added another script in front of it, somehow that might fix the glitch and open the dialogue box - and it did.  ;D
Code: [Select]
STDSizes=[
{'Size': 'TC.nobleed*','width':64,'height':89},
{'Size': 'TRADING.CARD.+3mm','width':70,'height':95},
{'Size': 'TC+2mm','width':68,'height':93},
{'Size': 'A0','width':841,'height':1189},
{'Size': 'A1','width':594,'height':841},
{'Size': 'A2','width':420,'height':594},
{'Size': 'A3*','width':297,'height':420},
{'Size': '*A4','width':210,'height':297},
{'Size': 'A5','width':148,'height':210},
{'Size': 'A6','width':105,'height':148},
{'Size': 'A7','width':74,'height':105},
{'Size': 'A8','width':52,'height':74},
{'Size': 'A9','width':37,'height':52},
{'Size': 'A10','width':26,'height':37},

{'Size': 'B0','width':1000,'height':1414},
{'Size': 'B1','width':707,'height':1000},
{'Size': 'B2','width':500,'height':707},
{'Size': 'B3','width':353,'height':500},
{'Size': 'B4','width':250,'height':353},
{'Size': 'B5','width':176,'height':250},
{'Size': 'B6','width':125,'height':176},
{'Size': 'B7','width':88,'height':125},
{'Size': 'B8','width':62,'height':88},
{'Size': 'B9','width':44,'height':62},
{'Size': 'B10','width':31,'height':44},

{'Size': 'C0','width':917,'height':1297},
{'Size': 'C1','width':648,'height':917},
{'Size': 'C2','width':458,'height':648},
{'Size': 'C3','width':324,'height':458},
{'Size': 'C4','width':229,'height':324},
{'Size': 'C5','width':162,'height':229},
{'Size': 'C6','width':114,'height':162},
{'Size': 'C7','width':81,'height':114},
{'Size': 'C8','width':57,'height':81},
{'Size': 'C9','width':40,'height':57},
{'Size': 'C10','width':28,'height':40},

{'Size': '4A0','width':1682,'height':2378},
{'Size': '2A0','width':1189,'height':1682},

{'Size': 'Letter','width':215.9,'height':279.4},
{'Size': 'Legal','width':215.9,'height':355.6},
{'Size': 'Junior Legal','width':203.2,'height':127},
//{'Size': 'Ledger','width':432,'height':279},
{'Size': 'Tabloid','width':279,'height':432},

{'Size': 'PA4','width':210,'height':280},

{'Size': 'Arch A','width':229,'height':305},
{'Size': 'Arch B','width':305,'height':457},
{'Size': 'Arch C','width':457,'height':610},                           
{'Size': 'Arch D','width':610,'height':914},
{'Size': 'Arch E','width':914,'height':1219},
{'Size': 'Arch E1','width':762,'height':1067},
{'Size': 'Arch E2','width':660,'height':965},
{'Size': 'Arch E3','width':686,'height':991},

{'Size': '2R','width':64,'height':89},
{'Size': 'LD,DSC','width':89,'height':119},
{'Size': '3R,L','width':89,'height':127},
{'Size': 'LW','width':89,'height':133},
{'Size': 'KGD','width':102,'height':136},
{'Size': '4R,KG','width':102,'height':152},
{'Size': '2LD,DSCW','width':127,'height':169},
{'Size': '5R,2L','width':127,'height':178},
{'Size': '2LW','width':127,'height':190},
{'Size': '6R','width':152,'height':203},
{'Size': '8R,6P','width':203,'height':254},
{'Size': 'S8R,6PW','width':203,'height':305},
{'Size': '11R','width':279,'height':356},
{'Size': 'A3+,Super B','width':330,'height':483}
];

STDSizes.sort(function(a, b) {
    return (a.height > b.height) ? -1 : ((b.height > a.height) ? 1 : 0);
});

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

var eps = 1; //size compare tolerance [mm]
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var PaperSizes = {};
    var File = pdfe.SelectedFiles(i);
    var Pages = File.Pages;
    var PortraitCount = 0;
    var LandscapeCount = 0;
    ProgressBar.position = i + 1;
    pdfe.echo(File.Filename);
    if (Pages.Count > 0) {
        for (var ii = 0; ii < Pages.Count; ii++) {
            var Page = Pages(ii);
            if (Page) {
                var w = Math.min(Page.Width, Page.Height);
                var h = Math.max(Page.Width, Page.Height);
                for (var n = 0; n < STDSizes.length; n++) {
                    hdif = h - STDSizes[n].height;
                    if (Math.abs(hdif) < eps && Math.abs(w - STDSizes[n].width) < eps) {
                        SizeID = STDSizes[n].Size;
                        if (!PaperSizes[SizeID]) {
                            var PaperSize = clone(STDSizes[n]);
                            PaperSize['count'] = 1;
                            PaperSizes[SizeID] = PaperSize;
                        } else {
                            PaperSizes[SizeID].count += 1;
                        }
                        break;
                    } else if (hdif > 0) { //stop search if page height>current stdSize height
                        var SizeID = w.toFixed() + ' x ' + h.toFixed();
                        var PaperSize = {
                            'Size': SizeID,
                            'width': Math.floor(w * 10) / 10,
                            'height': Math.floor(h * 10) / 10,
                            'notStd': true
                        }

                        STDSizes.splice(n, 0, PaperSize);
                        PaperSize['count'] = 1;
                        PaperSizes[SizeID] = PaperSize;
                        break;
                    }
                }

                (Page.Height > Page.Width) ? PortraitCount++ : LandscapeCount++;
            }
        }

        //sort descending by page size count. Standard sizes and higher heights first
        PaperSizes = sortObj(PaperSizes, function(a, b) {
            if (a['notStd'] == b['notStd']) {
                return (a.count > b.count) ? -1 : ((b.count > a.count) ? 1 : (a.height > b.height) ? -1 : ((b.height > a.height) ? 1 : 0));
            } else if (!a['notStd']) return -1;
            return 1;
        });


        var FileMetadata = File.Metadata;
        var Changed = false;

        var sizesStr = '';
        for (var n = 0; n < PaperSizes.length; n++) {
            sizesStr = sizesStr + PaperSizes[n].Size + ' ,';
        }

        sizesStr = sizesStr.substr(0, sizesStr.length - 1);
        if (FileMetadata.PageSize !== sizesStr) {
            FileMetadata.PageSize = sizesStr;
            Changed = true;
        }

        var PageOrientationStr = 'Portrait';
        if (PortraitCount && LandscapeCount) PageOrientationStr = 'Mixed'
        else if (LandscapeCount) PageOrientationStr = 'Landscape';

        if (FileMetadata.PageOrientation !== PageOrientationStr) {
            FileMetadata.PageOrientation = PageOrientationStr;
            Changed = true;
        }

        if (Changed) {
            if (FileMetadata.CommitChanges()) {
                pdfe.echo('      (Paper sizes: ' + sizesStr + ' - Orientation: ' + PageOrientationStr + ') [OK]');
            } else {
                pdfe.echo('      [commit changes failed]', 0xFF0000);
            }
        } else {
            pdfe.echo('      (Paper sizes: ' + sizesStr + ' - Orientation: ' + PageOrientationStr + ') [properties already set]');
        }

    } else {
        pdfe.echo('      [not a PDF or has no pages]', 0xFF0000);
    }
}

pdfe.echo("Done");

//======================================================================
function clone(obj) {
    if (obj == null || typeof(obj) != 'object') return obj;
    var temp = new obj.constructor();
    for (var key in obj)
    temp[key] = clone(obj[key]);
    return temp;
}

function sortObj(object, sortFunc) {
    var rv = [];
    for (var k in object) {
        if (object.hasOwnProperty(k)) {
            rv.push(object[k]);
        }
    }
    rv.sort(sortFunc);
    return rv;
}
var options = {
    params: []
};

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var Filename = pdfe.SelectedFiles(i).Filename;
    var fileOpt = {
        type: 'edit',
        name: i,
        label: '!Copies of ' + Filename,
        def: 1
    };
    options.params.push(fileOpt);
}

try {
    options = JSON.parse(pdfe.DialogBox(JSON.stringify(options)));
    if (options.Canceled) {
        pdfe.echo('canceled');
        pdfe.quit();
    }
} catch (err) {
    pdfe.quit();
}

var Merger = pdfe.CreateDocumentMerger();
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    var File = pdfe.SelectedFiles(i);
    var Filename = File.Filename;
    pdfe.echo(Filename);
    ProgressBar.position = i + 1;
    var copies = parseInt(options[i]) || 1;
    for (var n = 0; n < copies; n++)
    Merger.MergeDocument(Filename);
}

var dialog = pdfe.SaveDialog;
dialog.DefaultExt = '.pdf';
dialog.filter = 'PDF documents (*.pdf)|*.pdf';
dialog.Options = '[ofOverwritePrompt]';
dialog.Filename = Filename.substring(0, Filename.lastIndexOf('.')) + '_merged.pdf';
if (dialog.execute) {
    Merger.EndAndSaveTo(dialog.Filename);
    pdfe.echo('Done.');
}
Title: Re: More dynamic merge tool
Post by: RTT on November 06, 2020, 01:11:28 AM
That's interesting!
Try adding, instead of that script, a pdfe.sleep(2000); line or a pdfe.echo("starting"); one and try again.