Question

Im using this library to create Code39 barcodes...

http://barcode-coder.com/en/barcode-jquery-plugin-201.html

It has multiple output options, such as css, svg, canvas, bmp etc ....

I've set it to bmp as that is the only one that is an 'image'.

I figured Id be able to generate it, and then save to my computer. However, on output....when I right click the generated barcode no menu pops up.

Its not that theres no 'Save As Image' in the menu..., theres no menu....period.

What would be the cause of this, and is it possible to save Jquery generated images directly from the browser??

I understand that this isn't really a code related question, just wanted some insight as to wether you can actually download Jquery generated images, and possible answers if anyone knows, as to why it is that you can't.

Or do I need to apply another library, such as Canvas2Image. Which may allow me to take the canvas generated barcode, and save.

http://www.nihilogic.dk/labs/canvas2image/

Was it helpful?

Solution

You can set it to output to canvas then use something like this to save it as image:

HTML:

<a id="download" download="barcode.png">Download as image</a>

And in your Javascript:

function download() {
    var dt = canvas.toDataURL();
    this.href = dt;
}

var canvas = document.getElementById('myCanvasId');
document.getElementById('download').addEventListener('click', download, false);

When you now click the download as image button it will generate a PNG image file that you can save to disk.

OTHER TIPS

I just used the Canvas2Image workaround, it worked beautifully, but if anyone still wants to inform me as to why it is you can't save images generated by Jquery/Javascript, Im all ears.

I love learning how things work, or why they don't.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top