The next script will take as input a filename with a ".barcodes" filename extension (your 2500 alphanumeric codes in a text list), ask for the desired page width and height and create a PDF with equal number of pages as lines in the .barcodes file, stamped with these alphanumeric codes as barcode.
try {
var options = JSON.parse(pdfe.DialogBox(JSON.stringify({
params: [{
type: 'edit',
label: 'Page width [mm]:',
name: 'PageWidth',
def: 50
}, {
type: 'edit',
label: 'Page height [mm]:',
name: 'PageHeight',
def: 50
}]
})));
if (options.Canceled) {
pdfe.quit();
pdfe.echo('canceled');
}
options.PageWidth = parseIntDef(options.PageWidth, 50, 1, 1000);
options.PageHeight = parseIntDef(options.PageHeight, 50, 1, 1000);
} catch (err) {
pdfe.quit();
}
pdfe.echo('Working...');
var Merger = pdfe.CreateDocumentMerger();
Merger.MergeDocument(''); //to circumvent a bug in versions <=3.3
var BarcodeValuesFile = pdfe.Arguments(0);
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var objTextFile = objFSO.OpenTextFile(BarcodeValuesFile, 1 /*ForReading*/ , false, -1);
while (!objTextFile.AtEndOfStream) {
Merger.MergeBlankPage(options.PageWidth, options.PageHeight);
objTextFile.Readline();
}
objTextFile.Close();
var InputFolder = BarcodeValuesFile.substring(0, BarcodeValuesFile.lastIndexOf('\\') + 1);
var OutputPDFFilename = InputFolder + 'Barcodes.pdf';
Merger.EndAndSaveTo(OutputPDFFilename);
var STCmdlineExe = pdfe.FullName.substring(0, pdfe.FullName.lastIndexOf('\\') + 1) + 'PDFShellTools.exe';
var StampTemplate = InputFolder + 'StampBarcodesFromImportList.stp';
var objShell = new ActiveXObject("shell.application");
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.Run('"'+STCmdlineExe + '" stamp "template=' + StampTemplate + '" "DynCustomText=' + BarcodeValuesFile + '" "' + OutputPDFFilename + '"', 1, true);
WshShell.Run('"'+OutputPDFFilename+'"');
pdfe.echo('Done.', 0, 2);
/*****************************************************************/
function parseIntDef(value, def, min, max) {
var parsed = parseInt(value, 10);
if (isNaN(parsed)) {
return def
}
return Math.min(max, Math.max(min, parsed));
}
Attached is a zip file with some files needed to set this up. Extract the archived files to a working folder and proceed this way:
Using the PDF-ShellTools Manager scripts page
Import the script named "CreateBarcodesPDFFromValueList.myscript" from that working folder.
Close the script editor, confirming you want to save the changes.
Close the manager.
The Windows Explorer right click menu for the "barcodelist.barcodes" file should now show a "Create barcodes PDF from value list" item (1st attached screenshot). Execute it.
The script will execute, asking for the desired PDF page width and height to use. Click its OK button.
The stamp tool GUI will open, with the task ready to run.
For this first run, you need to setup a script for the dynamic data functionality. Click the "configure" named button (2nd screenshot).
The Dynamic Text Stamp Settings dialog will show up. On the left list select the "Scripts" section and click the "New" button.
The scripts editor will show up. Name the new script "SelectValueFromList".
In the code editor write this code:
var Numbers = [];
function SelectValueFromList(param) {
if (!Numbers.length) {
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var objTextFile = objFSO.OpenTextFile(param, 1 /*ForReading*/ , false, -1);
while (!objTextFile.AtEndOfStream) {
var strNextLine = objTextFile.Readline();
Numbers.push(strNextLine);
}
objTextFile.Close();
}
return Numbers[CurrentTask.PageNumber - 1];
}
Close the script editor, saving the changes.
You only need to do this this time, to add the script to the system.
Your stamp job is now ready to run. Hit the "stamp" (or "preview") button and the result PDF will open in your system default PDF reader, PDF file that is also saved in the same folder of the ".barcodes" file.
Attached I'm including a sample PDF generate by this setup.
To stamp you own barcode values, just run it against your own alphanumeric codes file. Just make sure the file name has no spaces in the name, and has a ".barcodes" filename extension.