Author Topic: barcode import list  (Read 149 times)

0 Members and 1 Guest are viewing this topic.

Nick Riviera

  • Newbie
  • *
  • Posts: 5
barcode import list
« on: September 30, 2019, 08:09:27 AM »
Hello everybody

Is it possible to import a custom list of codes into barcode section?
Thanks,

Nick

RTT

  • Administrator
  • *****
  • Posts: 837
Re: barcode import list
« Reply #1 on: October 01, 2019, 12:41:18 AM »
You can use a barcode stamp, with dynamic data that can be provided from the command line or by an internal script.
Check the next two forum threads, to get a better idea how this work. These examples are for text stamps, but it works the same way for stamping barcodes.
Adding custom text stamp, from command line.
Refering to the last page.
For a practical example on how to work it with your problem I need more details about it. Where are these codes (DB, text file, spreadsheet, ...), how these codes should be added to the PDFs, etc.

Nick Riviera

  • Newbie
  • *
  • Posts: 5
Re: barcode import list
« Reply #2 on: October 01, 2019, 08:36:21 AM »
Hi
I attached the examples I was talking about to make myself understood...
The pdf file is made up of 5+ blank pages and the code list  is  a text file
Many thanks

RTT

  • Administrator
  • *****
  • Posts: 837
Re: barcode import list
« Reply #3 on: October 01, 2019, 11:47:27 PM »
You continue without saying exactly what you want to do! Your sample PDF only has a barcode in the first page. Are the other codes, in the text sample list you provided, supposed to be stamped into the rest of the pages of the PDF?

Would a script that takes as input the text file with the list of barcode values and creates a new PDF document with all the codes in the list stamped as barcode into equal number of added blank pages work for what you need?

Nick Riviera

  • Newbie
  • *
  • Posts: 5
Re: barcode import list
« Reply #4 on: October 02, 2019, 07:15:49 AM »
Yes ,that's exactly what I want... if it's possible

For example,  I have 2500 alphanumeric codes in a text list.
I will create 2500 blank pdf pages then i stamp as barcode  each page whit all codes in the list...




Would a script that takes as input the text file with the list of barcode values and creates a new PDF document with all the codes in the list stamped as barcode into equal number of added blank pages work for what you need?

RTT

  • Administrator
  • *****
  • Posts: 837
Re: barcode import list
« Reply #5 on: October 03, 2019, 02:35:20 AM »
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.
Code: [Select]
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:
Code: [Select]
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.

Nick Riviera

  • Newbie
  • *
  • Posts: 5
Re: barcode import list
« Reply #6 on: October 03, 2019, 11:58:58 AM »
Thank you for your help and time!
I followed all the steps but receive an error at final step  when trying to create barcodes " Working...Error (48,0): "
I have attached a picture for an example...

RTT

  • Administrator
  • *****
  • Posts: 837
Re: barcode import list
« Reply #7 on: October 03, 2019, 02:36:32 PM »
Use the manager to edit the main script and change the lines 49..51 to:
Code: [Select]
WshShell.Run('"'+STCmdlineExe + '" stamp "template=' + StampTemplate + '" "DynCustomText=' + BarcodeValuesFile + '" "' + OutputPDFFilename + '"', 1, true);

WshShell.Run('"'+OutputPDFFilename+'"');
I've update my above post, to reflect this changes.

Nick Riviera

  • Newbie
  • *
  • Posts: 5
Re: barcode import list
« Reply #8 on: October 04, 2019, 08:51:02 AM »
Solved!
Thanks a lot!

Use the manager to edit the main script and change the lines 49..51 to:
Code: [Select]
WshShell.Run('"'+STCmdlineExe + '" stamp "template=' + StampTemplate + '" "DynCustomText=' + BarcodeValuesFile + '" "' + OutputPDFFilename + '"', 1, true);

WshShell.Run('"'+OutputPDFFilename+'"');
I've update my above post, to reflect this changes.