Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

labelmake

2.0.3 • Public • Published

Unit Testing

labelmake

top

labelmake is a declarative style PDF generation library for Node and the browser.

Description

I am developing labelmake.jp. That is PDF creation service that can do variable data printing.

I just realised in developing labelmake.jp that other PDF generation libraries makes program complex by imperative operations.

So, I developed this library aiming at a more simple declarative style PDF generation library and released it as OSS.

Installation

Use npm to install the latest version.

npm install labelmake

You can use Yarn, NuGet or other methods as well. You can load it directly from jsDelivr.

Demo

https://labelmake.jp/javascript-pdf-generator-library/example

Usage

Note: This usage is outdated, so please refer to the latest example folder. We will fix this section in the near future.

Data

template

{
  "pageSize": {
    "width": 100,
    "height": 100
  },
  "datas": [
    {
      "background": null,
      "schema": {
        "test1": {
          "position": { "x": 0, "y": 0 },
          "width": 50,
          "height": 50,
          "type": "qrcode"
        },
        "test2": {
          "position": { "x": 60, "y": 60 },
          "width": 50,
          "type": "text",
          "alignment": "left",
          "fontSize": 8,
          "characterSpacing": 0,
          "lineHeight": 1
        }
      }
    }
  ]
}

inputs

[{ "test1": "aa", "test2": "aa" }]

Node

const fs = require("fs");
const labelmake = require("labelmake");
const template = require("../template");
const inputs = require("../inputs");
 
labelmake({ template, inputs }).then((pdf) => {
  fs.writeFileSync(__dirname + "/my.pdf", pdf);
});

Browser

<html>
  <iframe id="iframe" width="100%" height="700"></iframe>
  <script src="https://cdn.jsdelivr.net/npm/labelmake/dist/labelmake.min.js"></script> 
  <script type="text/javascript" src="../template.js"></script> 
  <script type="text/javascript" src="../inputs.js"></script> 
  <script type="text/javascript">
    labelmake({ template, inputs }).then((buffer) => {
      const blob = new Blob([buffer.buffer], { type: "application/pdf" });
      document.getElementById("iframe").src = URL.createObjectURL(blob);
    });
  </script> 
</html>

Result

result

You can see demo in example folder.

Features

  • Template data Template data supports embedding of Image (jpeg, png) and SVG.
  • Input data supports the following input types.
    • Text(Uses the Roboto font by default. Can use custom fonts)
    • Image(jpeg, png)
    • SVG
    • Barcode(Checksum is calculated automatically)
      • QR Code
      • Japan Post 4 State Customer Code
      • EAN-13
      • EAN-8
      • Code 39
      • Code 128
      • Codabar(NW-7)
      • ITF-14

Documentation

Please see the following page for more information

Keywords

Install

npm i labelmake

DownloadsWeekly Downloads

54

Version

2.0.3

License

MIT

Unpacked Size

8.14 MB

Total Files

19

Last publish

Collaborators

  • avatar