
Я пытаюсь распечатать штрих-код метки В REACT JS... но проблема в том, что когда я пытаюсь распечатать, поля автоматически добавляются слева и справа, а ширина вообще не работает.
Я пытался создать PDF-файл со штрих-кодом, но это тоже не сработало.
Я пробовал добавить css и пробовал много чего, но это не исправилось.
КОД REACT
import React, { useEffect } from 'react';
import { Button, Col, Container, Navbar, Row } from 'reactstrap';
import JsBarcode from 'jsbarcode';
const PrintBarcodeCreate = () => {
const products = [
{ no: '546493176226', name: 'Mugdal 500gm', mrp: 1000, salePrice: 990, expDate: "10/10/2023" },
{ no: '546493176226', name: 'Mugdal 500gm', mrp: 1000, salePrice: 990, expDate: "10/10/2023" },
{ no: '546493176226', name: 'Mugdal 500gm', mrp: 1000, salePrice: 990, expDate: "10/10/2023" },
{ no: '546493176226', name: 'Mugdal 500gm', mrp: 1000, salePrice: 990, expDate: "10/10/2023" },
];
useEffect(() => {
document.title = "POS Create - Ajspire Technologies";
// Generate barcodes using JsBarcode
products.forEach(data => {
JsBarcode(`#barcode-${data.no}`, data.no, {
format: "CODE128",
displayValue: true,
fontSize: 10,
width: 1.2,
height: 25,
margin: 0,
});
});
}, []);
const handlePrint = () => {
const printWindow = window.open('', '_blank');
printWindow.document.write(document.getElementById('printable-area').innerHTML);
printWindow.document.close();
printWindow.print();
};
return (
Print Barcodes
{products.map((data, index) => (
index % 2 === 0 && (
Sai Mart
{data.name}
Sale ₹. {data.salePrice}
Exp : {data.expDate}
{products[index + 1] && (
Sai Mart
{products[index + 1].name}
Sale ₹. {products[index + 1].salePrice}
Exp : {products[index + 1].expDate}
)}
)
))}
);
};
export default PrintBarcodeCreate;
Подробнее здесь: https://stackoverflow.com/questions/768 ... n-react-js
Мобильная версия