librebarcode icon indicating copy to clipboard operation
librebarcode copied to clipboard

Text Encoder for Server Applications

Open mattsmac opened this issue 1 year ago • 1 comments

Hello, I was wondering if there is or could be a version of the encoder (https://graphicore.github.io/librebarcode/documentation/code128.html) that could be incorporated into a server application (c#). The encoder on the documentation page works flawlessly, but I'm having trouble trying to incorporate it into a hosted application that will need to generate the barcode text in a background process. Thank you!

mattsmac avatar Oct 13 '23 14:10 mattsmac

Hi @mattsmac there could certainly be an encoder written in C#, maybe there is one, I don't know.

When you say background process, it could be a Node.js script. The file path to encoder.mjs is relative to the examples, but the encoder.mjs module has no dependencies itself, so you can just put it next to the script that's inclusing it. In the examples, the scripts are in the repository root directory.

File: encode-node.sh:

#! /usr/bin/env node 
const process = require('node:process');
import('./app/lib/code128Encoder/encoder.mjs')
.then(({default:encode})=>{
    console.log(encode(process.argv[2] || ''));
});

usage:

$ ~/Projects/librebarcode>  ./encode-node.sh "Hello World!"
ÌHello World!WÎ

Or maybe with another JavaScript runtime, like Deno, which natively understands ES6-Modules:

File: encode-deno.sh:

#! /usr/bin/env -S deno run 
import encode from './app/lib/code128Encoder/encoder.mjs'
console.log(encode(Deno.args[0] || ''));

usage:

$ ~/Projects/librebarcode>  ./encode-deno.sh "Hello World!"
ÌHello World!WÎ

graphicore avatar Oct 20 '23 10:10 graphicore