Printing Multiple PDFs from Java as a single print job (physical printing)

前端 未结 4 468
谎友^
谎友^ 2021-01-06 15:18

I would like to print multiple pdfs from java (using the java print service) in a single print job.

I would like to send multiple pdfs as a single job to the printe

相关标签:
4条回答
  • 2021-01-06 15:36

    I met the same difficulties when printing at once several JPanels of a JTabbedPane, each on a separate page. I gather them in a Book but it only prints the first page.

    The Book class works well (right number of pages), but I suppose the problem comes from setPageable. Since a Book is not a Printable, I made it, and it works !

    Workaround:

    1. Design a PrintableBook class : extends Book, implements 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);
              }
          }
      }
      
    2. Then use printJob.setPrintable( printableBook ) instead of setPageable

    0 讨论(0)
  • 2021-01-06 15:40

    You should merge all of your pdf documents in one document using iText library and then print the merged document page by page.

    see Print a PDF Document in Java

    0 讨论(0)
  • 2021-01-06 15:48

    Not Java specific, but I've experience of this one in C#. I solved it by printing each document to a file (programmatically equivalent to checking the "PrintToFile" checkbox on a print dialog), then concatenated each file into a memory stream, which I passed to the Win32 API printer spool in raw format (since the output to file was already correctly formatted by default).

    You might be able to use a similar technique in Java

    0 讨论(0)
  • 2021-01-06 15:48

    AFAIK, you can't, multiple documents will be printed in multiple jobs.

    A workaround could be join all the pdf into a single document and print them.

    :-/

    0 讨论(0)
提交回复
热议问题