guys.
I'm currently finding so much trouble trying to print a freshly generated PDF with jsPDF tools. First and foremost, I must clarify that I'm not trying to print automatically or autonomously. I'm building an Angular-based website from which certain users must be able to press a printer button and directly print. This website and feature must be accesible from PC, Android or iOS.
I've been trying many things, from the autoPrint() method that jsPDF offers to embedding the generated PDF to a new window and printing it. But none worked fine, or in the three types of device simultaneuosly.
This is some of my code, once all the data has been succesfully generated and is ready to be converted into PDF.
This was my first approach, but it just manages to save the PDF and then, manually, having to print it, which isn't efficient enough.
const doc = new jsPDF('p', 'mm', [80, 80]);
[...]
doc.autoPrint();
doc.save(`TicketMesa${idmesa + 1}_${fechaActual}_${horaActual}.pdf`);
Then, I tried to get it as an output from jsPDF, with no result in Android, as it gets blocked, by whatever reason that I cannot comprehend.
const doc = new jsPDF('p', 'mm', [80, 80]);
[...]
doc.autoPrint();
doc.output('dataurlnewwindow');
Finally, this is the embedded test that I've been working on based on different sources from within SO. (With and without the commented lines)
const dataSrc = doc.output('datauristring');
const embed = '<embed width=\'100%\' height=\'100%\' src=\'' + dataSrc + '\'/>';
const newWin = window.open();
newWin.document.write(embed);
// newWin.document.close();
// newWin.focus();
// newWin.print();
// newWin.close();
What I'm exactly trying to achieve is replicate the behaviour of these kind of kiosk-mode machines that can print tickets pressing just one button. I've seen it work, with iOS and Android, so it has to be possible.
This is an example of what I say, sorry it's in Spanish, but he doesn't explain much anyway: https://www.youtube.com/watch?v=pNfy9gEn7f4&t=0s
Thank you so much for you attention and possible help. Cheers, guys.