Displaying barcodes
Repeat the previous step
You have learned how to save the barcode to a file. If you prefer to display it on the screen, you simply need to change the last part of your script.
Output the stream
We use the same BCGDrawing class.
Use the third argument of the toBuffer method to write to a specific stream.
import { toBuffer } from '@barcode-bakery/barcode-nodejs';
/* ... */
toBuffer(drawing, BCGDrawing.ImageFormat.Png, function (err, buffer) {
/*
* Use buffer, write it to the response.
*/
});
Remember if you output the image to a browser, you must not have output anything else to the stream beforehand.
One common mistake is to try to display the barcode stream directly in an HTML page.