reactjsprintingthermal-printerpoint-of-saleprintjs

Trying to print on thermal printer using print.js


Trying to print a pdf receipt, but it adds empty spaces on top and bottom.

const responseBlob = new Blob([pdfBlob], {
    type: 'application/pdf'
  });
  const fileURL = URL.createObjectURL(responseBlob);
  setPreview(false);
  // printJS(fileURL);
  printJS({
    type: 'pdf',
    printable: fileURL,
    honorMarginPadding: true,
    style: '@page { size: 80mm 50mm }'

  });

But I am getting print like this.

enter image description here

PDF file

enter image description here

Solution: Instead of PrintJS, use https://www.npmjs.com/package/react-to-print


Solution

  • This should resolve the issue These adjustments should help in eliminating any unwanted spacing and ensuring that the content fits within a single page with the specified page size of 80mm printJS({ printable: receiptRef.current, type: 'html', scanStyles: false, style: @page { size: 80mm 100%; margin: 0; } body { margin: 0; } /* Additional styles to ensure no unwanted spacing */ html, body, #root, #root > div { margin: 0; width: 100%; height: 100%; overflow: hidden; }, });