0% found this document useful (0 votes)
2 views

bar cade generater by python

The document contains an HTML and JavaScript implementation of a barcode generator that allows users to input product names and quantities, generating corresponding barcodes displayed on the webpage. It also includes a Python script for generating barcodes programmatically using the 'barcode' library, saving them as images. The barcode data is formatted as 'productName-price-quantity' and supports printing functionality.

Uploaded by

ravi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

bar cade generater by python

The document contains an HTML and JavaScript implementation of a barcode generator that allows users to input product names and quantities, generating corresponding barcodes displayed on the webpage. It also includes a Python script for generating barcodes programmatically using the 'barcode' library, saving them as images. The barcode data is formatted as 'productName-price-quantity' and supports printing functionality.

Uploaded by

ravi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

<!

DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-


scale=1.0">

<title>Barcode Generator</title>

<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/JsBarcode.all.min
.js"></script>

<style>

body {

font-family: Arial, sans-serif;

text-align: center;

padding: 20px;

input {

width: 50%;

padding: 10px;

font-size: 16px;

margin: 10px;

button {

margin: 10px;

padding: 10px;

font-size: 16px;

cursor: pointer;

}
.barcode-container {

margin-top: 20px;

display: flex;

flex-wrap: wrap;

justify-content: center;

.barcode-box {

text-align: center;

margin: 10px;

padding: 10px;

border: 1px solid #000;

#printButton {

display: none;

</style>

</head>

<body>

<h2>Barcode Generator</h2>

<input type="text" id="productName" placeholder="Enter product name">

<input type="number" id="quantity" placeholder="Enter quantity


(grams)">

<button onclick="addProduct()">Add Product</button>

<button id="printButton" onclick="printBarcodes()">Print


Barcodes</button>
<div id="barcodeContainer" class="barcode-container"></div>

<script>

function addProduct() {

let productName =
document.getElementById("productName").value.trim();

let quantity =
document.getElementById("quantity").value.trim();

let barcodeContainer =
document.getElementById("barcodeContainer");

if (productName === "" || quantity === "") {

alert("Please enter product name and quantity.");

return;

quantity += "gm"; // Automatically add "gm" to quantity

let barcodeData = `${productName}-${quantity}`;

let barcodeBox = document.createElement("div");

barcodeBox.classList.add("barcode-box");

barcodeBox.innerHTML = `

<p>${productName} - ${quantity}</p>

<svg></svg>

`;

barcodeContainer.appendChild(barcodeBox);

JsBarcode(barcodeBox.querySelector("svg"), barcodeData, {
format: "CODE128",

lineColor: "#000",

width: 2,

height: 50,

displayValue: true

});

document.getElementById("printButton").style.display =
"inline-block";

function printBarcodes() {

let printContent =
document.getElementById("barcodeContainer").innerHTML;

let originalContent = document.body.innerHTML;

document.body.innerHTML = `<div style="text-align: center;">$


{printContent}</div>`;

window.print();

document.body.innerHTML = originalContent;

location.reload();

</script>

</body>

</html>

import barcode

from barcode.writer import ImageWriter


def generate_barcode(product_name, price, quantity, save_path="barcodes/"):

# Format the barcode data

barcode_data = f"{product_name[:10]}-{price}-{quantity}"

# Generate barcode

code128 = barcode.get_barcode_class('code128')

barcode_instance = code128(barcode_data, writer=ImageWriter())

# Save the barcode as an image

file_path = save_path + barcode_data

barcode_instance.save(file_path)

print(f"Barcode saved at {file_path}.png")

return file_path + ".png"

# Example usage

if __name__ == "__main__":

product_name = input("Enter product name: ")

price = input("Enter product price: ")

quantity = input("Enter product quantity: ")

generate_barcode(product_name, price, quantity)


import barcode

from barcode.writer import ImageWriter

def generate_barcode(product_name, price, quantity, save_path="barcodes/"):

# Format the barcode data

barcode_data = f"{product_name[:10]}-{price}-{quantity}"

# Generate barcode

code128 = barcode.get_barcode_class('code128')

barcode_instance = code128(barcode_data, writer=ImageWriter())

# Save the barcode as an image

file_path = save_path + barcode_data

barcode_instance.save(file_path)

print(f"Barcode saved at {file_path}.png")

return file_path + ".png"

You might also like