Printing PDF or PNG in POS Thermal printer with java

2.9k Views Asked by At

I Everyone. I have a problem printing ticket with java. I generated ticket with jasper and then I need to print it in POS Thermal printer. I try to print PDF and the result got Wrong Format Then I convert pdf to png with pdfbox but the image print too small. How can I print correctly? Is there any way to print PDF for POS Thremal Printer correctly or fill and increase the PNG Image?

Print PNG too small

Printing from Adobe reader directly to my POS Thermal Printer, I had the correctly ticket. Correct from Adobe Reader

Here's part of my code:

PDDocument document = PDDocument.load(new File(pathFile+".pdf"));
            PDPage pd;

            PDFRenderer pdfRenderer = new PDFRenderer(document);

            for (int page = 0; page < document.getNumberOfPages(); ++page)
            {
              pd = document.getPage(page);
              BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
              ImageIOUtil.writeImage(bim, pathFile +".png", 300);

            }
            document.close();

            FileInputStream is = new FileInputStream(pathFile+".png");

            DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
            DocPrintJob job = mPrinter.createPrintJob();
            Doc doc = new SimpleDoc(is, flavor, null);

            job.print(doc, null);

            is.close();
0

There are 0 best solutions below