graphicore / librebarcode

Libre Barcode: barcode fonts for various barcode standards.
https://graphicore.github.io/librebarcode
SIL Open Font License 1.1
421 stars 25 forks source link

Text Encoder for Server Applications #58

Open mattsmac opened 11 months ago

mattsmac commented 11 months ago

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!

graphicore commented 10 months ago

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Î