Print multiple PDF files with Java as a single print job (physical print)

I would like to print several PDF files from java (using the java print service) in one print job.

I would like to send several PDF files as a single job to the printer. This means that all the documents in my "batch" print together and do not alternate with someone else when I pick them up from the printer.

The package potentially consists of 1000 print jobs.

I tried jpedal but it does not support java.awt.print.Book

        Book book = new Book();
        PdfDecoder pdfDecoder = readFileApplyOptions("C:/Temp/singlepagetest.pdf", pageFormat);
        book.append(pdfDecoder, pageFormat);

        PdfDecoder pdfDecoderTwo = readFileApplyOptions("C:/Temp/printfax-test.pdf",pageFormat);
        book.append(pdfDecoderTwo, pageFormat);

        printJob.setPageable(book);
        printJob.print();

Only the first PDF file is output. How to print multiple PDF files in one job?

readFileAndApplyOptions () basically creates a new PdfDecoder object and returns it.

Sun PDFRenderer PDFRenderer ( Book), - .

- ? , ?

+3
4

Java, #. , ( "PrintToFile" ), , Win32 API ( ).

, Java

+2

JPanels JTabbedPane, . , .

Book ( ), , setPageable. , , !

:

  • PrintableBook: Book, Printable

    public class PrintableBook extends Book implements Printable {
        Vector<Printable> pages;// NB: we assume pages are single
    
        public PrintableBook() {
            super();
            pages = new Vector<Printable>();
        }
    
        public void add(Printable pp) {
            append(pp, pp.getPageFormat());
            pages.add(pp);
        }
    
        public int print(Graphics g, PageFormat pf, int pageIndex) {
            if (pageIndex >= pages.size())
                return NO_SUCH_PAGE;
            else {
                Printable pp = pages.elementAt(pageIndex);
                return pp.print(g, pf, 0);
            }
        }
    }
    
  • printJob.setPrintable( printableBook ) setPageable

+2
+1
source

AFAIK, you cannot, several documents will be printed in several tasks.

A workaround is to combine all PDF documents into one document and print them.

: - /

0
source

Source: https://habr.com/ru/post/1706849/


All Articles