Code Monkey home page Code Monkey logo

qrcode-sfmc-ssjs's Introduction

QR Code Generator for Salesforce Marketing Cloud

A Server-Side JavaScript (SSJS) application for use in email and landing pages.

QR Code Sample

Supported Formats

  • HTML Table
  • Scalable Vector Graphics (SVG)

Examples

<script runat="server">

    <!-- src/qrcode.sfmc.ssjs.js -->

    var qrCodeHTMLTable = new QRCode("https://www.salesforce.com").table();
    
    Write(qrCodeHTMLTable);

    var qrCodeSVG = new QRCode({
        "content" : "https://www.salesforce.com",
        "padding" : 0,
        "width": 300,
        "height": 300,
        "color": "black",
        "background": "white",
        "ecl" : "L",
        "pretty" : false
    }).svg();
    
    Write("<br>");
    Write(qrCodeSVG);

</script>

Options

Name Default Required Description
content undefined Yes The text string/URL to encode (e.g., https://www.salesforce.com)
width 300 No The width of the QR code, in pixels
height 300 No The height of the QR code, in pixels
color #000000 No The color name/hex value of the data modules
background #ffffff No The color name/hex value of the background
ecl L No The error correction level of the QR code
pretty true No Apply indents and new lines to returned text

HTML Table-only Options

Name Default Required Description
inlineStyle true No Apply inline CSS to the HTML table and each data cell element using the options above. Setting this to false removes the width, height, color, and background options, forcing you to recreate them outside the QR code with a style sheet. Given the file size constraints of email, false is recommended.

SVG-only Options

Name Default Required Description
padding 0 No The amount of white space around the image, in modules
join false No Join modules into one SVG path, i.e. for crisp rendering
predefined false No Use 'defs' and 'use' elements in SVG, i.e. for compact output
xmlDeclaration false No Prepend XML declaration to the SVG document
container svg No Wrapping element (svg/svg-viewbox/g/none; see below)

SVG container options:

  • svg - populate squares in a SVG document with width and height attribute, recommended for converting to raster images or PDF where QR Code is being static (exact size)
  • svg-viewbox - populate squares in a SVG document with viewBox attriute, recommended for responsive web pages
  • g - put squares in g element, useful when you need to put multiple QR Codes in a single SVG document
  • none - no wrapper

Version History

This repo is a fork of qrcode-svg, itself a fork of qrcodejs. Both use client-side JavaScript to render QR codes in the browser, whereas this library is intended to run on the Marketing Cloud server. To make this possible, each function was downgraded to ECMAScript 3, removing references to the DOM along with unsupported features and keywords. Further optimizations and bug fixes can be submitted via a pull request.

qrcode-sfmc-ssjs's People

Contributors

jp-ed avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.