Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Building a Zero-Signup Rule 46 GST Tax Invoice Generator in React with A4 Vector PDFs

Every small business owner, freelancer, and consultant in India eventually confronts the same administrative roadblock: generating a compliant GST Tax Invoice without paying for bloated desktop accounting software. Unde

Every small business owner, freelancer, and consultant in India eventually confronts the same administrative roadblock: generating a compliant GST Tax Invoice without paying for bloated desktop accounting software.

Under Section 31 of the CGST Act, 2017 and Rule 46 of the CGST Rules, 2017, an Indian tax invoice must satisfy strict statutory requirements:

  1. Distinct serial numbers (consecutive and unique for the financial year).
  2. Supplier and recipient GSTIN, PAN, and full address.
  3. Official Place of Supply (POS) with state name and 2-digit statutory state code.
  4. Correct tax segregation: Intra-State (50% CGST + 50% SGST) vs. Inter-State (100% IGST).
  5. 6-digit or 8-digit HSN/SAC codes with aggregated tax rate summaries.
  6. Statutory total amount expressed in Indian numbering words (Lakhs and Crores, not Millions).

We recently open-sourced and shipped a 100% free, zero-signup web utility at QRBX GST Invoice Maker. Here is how we engineered the core statutory logic and vector print architecture.

1. Place of Supply (POS) & Tax Segregation Algorithm

Under Indian GST laws, whether you levy CGST+SGST or IGST depends solely on whether the Place of Supply (POS) matches the supplier's registered state:

export interface TaxSplit {
  isInterstate: boolean;
  cgstRate: number;
  cgstAmount: number;
  sgstRate: number;
  sgstAmount: number;
  igstRate: number;
  igstAmount: number;
}

export function calculateStatutoryTax(
  sellerStateCode: string,
  placeOfSupplyCode: string,
  taxableValue: number,
  gstRate: number
): TaxSplit {
  // Intra-State supply: Supplier and Place of Supply are in the same state
  const isInterstate = sellerStateCode !== placeOfSupplyCode;

  if (isInterstate) {
    return {
      isInterstate: true,
      cgstRate: 0,
      cgstAmount: 0,
      sgstRate: 0,
      sgstAmount: 0,
      igstRate: gstRate,
      igstAmount: (taxableValue * gstRate) / 100,
    };
  }

  // Intra-State supply: Tax is equally divided into Central (CGST) and State (SGST)
  const halfRate = gstRate / 2;
  const halfTax = (taxableValue * halfRate) / 100;

  return {
    isInterstate: false,
    cgstRate: halfRate,
    cgstAmount: halfTax,
    sgstRate: halfRate,
    sgstAmount: halfTax,
    igstRate: 0,
    igstAmount: 0,
  };
}

2. Converting Amounts into Indian Numbering Words (Lakhs & Crores)

Standard Western algorithms partition numbers in groups of thousands (1,000,000 = One Million). Indian statutory invoices require the Vedic numbering format (1,00,000 = One Lakh; 1,00,00,000 = One Crore).

export function numberToIndianWords(num: number): string {
  if (num === 0) return "Zero Rupees Only";

  const ones = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
    "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"];
  const tens = ["", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];

  function convertTwoDigits(n: number): string {
    if (n < 20) return ones[n];
    return `${tens[Math.floor(n / 10)]} ${ones[n % 10]}`.trim();
  }

  function convertThreeDigits(n: number): string {
    const hundred = Math.floor(n / 100);
    const rest = n % 100;
    const parts: string[] = [];
    if (hundred > 0) parts.push(`${ones[hundred]} Hundred`);
    if (rest > 0) parts.push(convertTwoDigits(rest));
    return parts.join(" ");
  }

  const integerPart = Math.floor(Math.abs(num));
  const paise = Math.round((Math.abs(num) - integerPart) * 100);

  const crore = Math.floor(integerPart / 10000000);
  const lakh = Math.floor((integerPart % 10000000) / 100000);
  const thousand = Math.floor((integerPart % 100000) / 1000);
  const remainder = integerPart % 1000;

  const result: string[] = [];
  if (crore > 0) result.push(`${convertThreeDigits(crore)} Crore`);
  if (lakh > 0) result.push(`${convertThreeDigits(lakh)} Lakh`);
  if (thousand > 0) result.push(`${convertThreeDigits(thousand)} Thousand`);
  if (remainder > 0) result.push(convertThreeDigits(remainder));

  let text = `INR ${result.join(" ")} Rupees`;
  if (paise > 0) {
    text += ` and ${convertTwoDigits(paise)} Paise`;
  }
  return `${text} Only`;
}

3. Pixel-Perfect A4 Vector PDF Generation Without Bloat

Rather than bundling bulky client-side canvas renderers that produce blurry rasterized PDFs, we isolate the printable DOM into a dedicated print stylesheet:

@page {
  size: A4 portrait;
  margin: 8mm 10mm;
}

@media print {
  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    width: 100% !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .no-print {
    display: none !important;
  }
  .invoice-sheet {
    box-shadow: none !important;
    border: none !important;
    max-width: 100% !important;
    margin: 0 auto !important;
  }
}

When triggered, Chrome, Safari, and Edge instantly render sharp, selectable-text vector PDFs in under 100 milliseconds.

Live Tools & Resources

If you have feedback or want more statutory templates (Export Invoices with LUT, Bill of Supply for Composition dealers), let us know in the comments!

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.