So, I need to print a PDF directly to the printer, because I need to print invoices. If I use this form Desktop d = Desktop.getDesktop().print("Caminho do arquivo")
it prints normally the first time, but opens the adobe together and the adobe closes the document and from there when I print again, it "buga" and prints everything that is in the extremely small PDF. And the idea is to print directly and in the size of the paper.
I have these 3 printers: Bematech MP 4200 TH, Bematech MP 4000 TH e MP2500TH.
Below is how I learned to print directly from the printer.
PrintService iPadrao = PrintServiceLookup.lookupDefaultPrintService();
DocFlavor docFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
try {
FileInputStream stream = new FileInputStream("C:\Users\EX-PHP\Documents\TestePDF2\vai.pdf");
Doc doc = new SimpleDoc(stream, docFlavor, null);
DocPrintJob p = iPadrao.createPrintJob();
p.print(doc, null);
} catch (PrintException e) {
e.printStackTrace();
}
The PDF in question contains an invoice containing a QR code. Also I tried with PDFRenderer, and with some codes that I found on the internet but without success, it could be some error in the codes or something that is missing.