npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

label-generator-backend

v1.1.0

Published

Label Generator Backend Service and Library for generating PDF labels from templates

Readme

Label Generator Library

npm version Node.js

Biblioteka za generisanje PDF labela iz template konfiguracija i podataka. Podržava tekst, barcode, QR kodove, slike i druge elemente sa varijabilnim podacima.

⚠️ Važno: Backend Only

Ova biblioteka može se koristiti SAMO na backendu (Node.js), ne u browseru!

Razlog: Biblioteka koristi Puppeteer za generisanje PDF-a, koji zahteva Node.js okruženje i ne može raditi u browseru.

Kako koristiti na frontendu?

  • Opcija 1: Kreiraj backend API endpoint koji koristi biblioteku
  • Opcija 2: Koristi serverless funkciju (AWS Lambda, Vercel Functions, itd.)

Vidi FRONTEND_USAGE.md za detalje.

Instalacija

npm install label-generator-backend

Brzi start

import { generatePdf } from 'label-generator-backend/lib'
import { writeFile } from 'fs/promises'

// Template konfiguracija
const templateConfig = {
  canvas: {
    width: 100,  // mm
    height: 50,  // mm
    unit: 'mm',
    dpi: 300
  },
  print: {
    format: 'sheet',
    document: {
      paperSize: 'A4',
      gridRows: 2,
      gridColumns: 2,
      gap: 5
    }
  },
  nodes: [
    {
      id: 'text1',
      type: 'text',
      position: { x: 10, y: 10 },
      size: { width: 80, height: 20 },
      props: {
        content: '{{productName}}',
        fontSize: 12,
        color: '#000000',
        align: 'center'
      }
    },
    {
      id: 'barcode1',
      type: 'barcode',
      position: { x: 10, y: 30 },
      size: { width: 80, height: 15 },
      props: {
        format: 'code128',
        value: '{{barcode}}',
        displayValue: true
      }
    }
  ]
}

// Podaci za labele (jedan objekat po labeli)
const data = [
  { productName: 'Proizvod 1', barcode: '1234567890123' },
  { productName: 'Proizvod 2', barcode: '1234567890124' },
  { productName: 'Proizvod 3', barcode: '1234567890125' },
  { productName: 'Proizvod 4', barcode: '1234567890126' }
]

// Generiši PDF
const result = await generatePdf(templateConfig, data)

if (result.success && result.pdf) {
  await writeFile('labels.pdf', result.pdf)
  console.log('PDF uspešno generisan!')
} else {
  console.error('Greška:', result.error)
}

API

generatePdf(templateConfig, data, options?)

Generiše PDF iz template konfiguracije i podataka.

Parametri

  • templateConfig (TemplateConfig): Konfiguracija template-a

    • canvas: Dimenzije i postavke canvas-a (labela)
    • print: Postavke štampe (format, paper size, grid, itd.)
    • nodes: Niz elemenata labela (text, barcode, qr, image, rectangle, line, addressBlock)
  • data (DataRow[]): Niz objekata sa podacima (jedan objekat po labeli)

    • Svaki objekat može sadržati bilo koje polje koje se koristi u template-u sa {{variableName}} sintaksom
  • options (ExportOptions?): Opcione postavke eksporta

    • page: Dimenzije stranice (overriduje template postavke)
    • grid: Grid postavke (overriduje template postavke)
    • dpi: Rezolucija (overriduje template postavke)
    • labelSize: Dimenzije labela (overriduje template postavke)

Povratna vrednost

interface GeneratePdfResult {
  success: boolean
  pdf?: Buffer        // PDF buffer (ako je success === true)
  error?: string      // Poruka greške (ako je success === false)
  status: 'success' | 'error'
}

Tipovi elemenata

Biblioteka podržava sledeće tipove elemenata:

  • text - Tekst sa varijablama, wrapping, alignment
  • barcode - Code128, Code39, EAN13, QR, DataMatrix, itd.
  • qr - QR kodovi sa error correction
  • image - Slike (base64 data URLs)
  • rectangle - Pravougaonici sa border radius, stroke, fill
  • line - Linije sa različitim stilovima
  • addressBlock - Blokovi adresa (name, street, zip, city, country)

Vidi LIBRARY_README.md za detaljnu dokumentaciju svih tipova.

Varijable

Template podržava varijable u formatu {{variableName}}. Sve varijable se zamenjuju sa vrednostima iz data objekta.

Primer:

  • Template: "Proizvod: {{productName}}"
  • Data: { productName: 'Laptop' }
  • Rezultat: "Proizvod: Laptop"

Format štampe

Single format

Jedna labela po stranici. Dimenzije stranice su jednake dimenzijama labela.

Sheet format

Više labela po stranici u grid formatu. Podržava različite veličine papira:

  • A4, A5, A6
  • Letter
  • Receipt-58mm, Receipt-80mm
  • Roll-* (custom roll dimenzije)
  • Custom (custom dimenzije)

Zahtevi

  • Node.js >= 22.16
  • npm ili yarn

Zavisnosti

Biblioteka koristi sledeće npm pakete:

  • pdf-lib: Za manipulaciju PDF-om
  • puppeteer: Za renderovanje HTML-a u PDF
  • bwip-js: Za generisanje barcode-ova
  • qrcode: Za generisanje QR kodova

Korišćenje iz drugih jezika

PHP

Vidi PHP_USAGE.md za detalje.

$generator = new LabelGenerator('http://localhost:3001');
$result = $generator->generatePdf($templateConfig, $data);

Python, Java, itd.

Kreiraj REST API endpoint koji koristi biblioteku i pozovi ga iz bilo kog jezika.

Vidi api-server-example.js za primer API servera.

Ograničenja

  • Maksimalno 500 labela se obrađuje u jednom chunk-u (automatski se deli na više chunk-ova za veće količine)
  • Sve slike moraju biti u base64 formatu (data URLs)
  • Template mora biti validan JSON objekat
  • Biblioteka radi samo u Node.js okruženju (ne u browseru)

Dokumentacija

Primeri

Vidi api-server-example.js i php-example.php za kompletan primer korišćenja.

Licenca

[Unesite licencu ovde]

Podrška

Za probleme i pitanja, otvorite issue na GitHub-u ili kontaktirajte autora.