1

I have a small Java programm, in which I generate a Pdf and later I print the PDF with the PDF Box tool an the Java Printer Job. I use a brother label printer.

When I press the button to execute the print method, windows open the printer queue and the print job is in progress, but noting print. I think the reason is that the file in the printer job is 0kb and the pages column in the windows queue is "n/a".

Affter a few minutes, the print job in the queue has now a specific size and the printer begins to print. When I execute the print method for a second time, the print job in the windows print queue has immideatly a specific size and the printer starts directly to print.

So I want to know what's the reason for this delay at the first time printing. It must be a Java Problem because if I print directly from the PDF Reader, there isn't a delay at the first time.

Here is my Java Code:

private static void printpdf_1 ()
            throws IOException, PrinterException
            {

            File file = new File("C:\\Users\\Public\\order_1.pdf") ;
            PDDocument document =PDDocument.load(file);


             PrinterJob job = PrinterJob.getPrinterJob();
                job.setPageable(new PDFPageable(document));

                // define custom paper
                Paper paper = new Paper();
                paper.setSize(148, 324); // 1/72 inch früher 142
                paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); // no margins

                // custom page format
                PageFormat pageFormat = new PageFormat();
                pageFormat.setPaper(paper);

                // override the page format
                Book book = new Book();
                // append all pages
                book.append(new PDFPrintable(document), pageFormat, document.getNumberOfPages());
                job.setPageable(book);

                job.print();

            }

Thank you for your help

Regards

Samuel

0 Answers0