Print PDF files

If you need to print the PDF files directly from UI Bakery, it can be achieved the following way:

  1. connect a JS library https://printjs.crabbly.com/#documentation in the Custom Code tab:

 <script src="https://printjs-4de6.kxcdn.com/print.min.js"></script>

2. Add a Code action and specify a similar code:

function getBase64(file) {
  return new Promise((resolve, reject) =>{
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => {
     resolve(reader.result);
    };
    reader.onerror = (error) => {
     reject(error);
    };
  })
}
	
const base64 = await getBase64({{ui.pdfFileInput.value[0]}})
	
printJS({
  printable: base64.replace('data:application/pdf;base64,', ''),
  type: 'pdf',
  base64: true
});

where ui.pdfFileInput.value is an input component with field type=file.

Last updated