Add a "Download" button below the generated code (optional setting)

Created on 20 February 2025, about 2 months ago

Problem/Motivation

First thank you so much for this unbelievable project! This is really huge and great work!

Barcodes / QR-Codes from this module are used in various ways. One way we ran into is using it for generating QR-Codes for Drupal nodes that the client can download and print.
As sometimes a QR-Code or barcode isn't really helpful on a digital device, but very useful when printed somewhere for referencing a digital representation, I think it would be great UX to add an optional setting to show a "Download" button below the generated code.

That way, regular users are able to download the generated QR-Code without having to understand how to download manually (right click > Save ...)

If you like the idea, we'd be happy to provide a MR for the various outputs.

Thanks!

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Anybody
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Especially for SVG images it would be helpful, as they are currently inline and the browser does not allow downloading it easily.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Here are some ways how an inline SVG could be converted into a download using JavaScript:
    https://stackoverflow.com/questions/43804171/how-to-extract-svg-as-file-...
    https://www.beaubus.com/blog/how_to_save_inline_svg_as_png_with_vanilla_...

    Another alternative would be to provide the download server-side, similar to the PNG?

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    If you like the idea, we'd be happy to provide a MR for the various outputs.

    Yes, I would absolutely like to have this feature and would be happy to work with you to get it into this module in a way that is useful.

    If you take a look at drush help barcodes:generate, you will see that there is a --binary output option for the PNG format. It would be easy enough to add an option to link the barcode to a binary image download, in the PNG output format, regardless of which format was chosen for the web display. So you could use the SVG inline format for web pages but return a binary PNG from the link.

    It would also be easy enough to add a REST resource to return a barcode in any of the supported formats. I actually did this once on my test site just for debugging purposes.

    The source code for this module's drush command is useful as an example if you want to implement either the link or the REST resource.

    Supporting binary download in a format other than PNG would take a little more doing. The PNG binary format is supported by the underlying tecnickcom/tc-lib-barcode library, but no other binary format is directly supported.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @tr thanks! I'll add it to our roadmap.
    For the .png it might be even easier, using the HTML5 download attribute for links: <a href="x.png" download>Download</a>

    I didn't try it for images yet, but I think it might work!
    The svg might be the hardest part, but I think it's important to also support that to have it as a real .svg for download to print and edit as-is.

Production build 0.71.5 2024