tags:

views:

1281

answers:

4

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 printer. This is so that all the documents in my 'batch' print together and are not interleaved with someone else's print jobs when I go pick them up from the printer.

A batch potentially consists of 1000s of 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 prints out the first pdf. How do I print multiple pdfs in a single job?

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

I also tried Sun's PDFRenderer PDFRenderer in a similar fashion (using the Book object), but my code still only prints out the first page only.

Has anyone encountered a similar issue before? Is there a solution I might be missing?

A: 

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.

:-/

OscarRyz
+1  A: 

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

Rob Cowell
A: 

Hi NiceGuyUK,

Could you please provide a sample of your code? I'm looking to do something similar. I have a folder with multiple pdf files and I'd like to send them to the printer as one job so that they are printed uninterupted. Your solution sounds ideal.

Duncan
You should probably put this as a comment to NiceGuyUK's response, and not as an answer to the main question.
Dean J
Sorry I dont know how to do that? This post has the option to add a comment to it, but the one below for example, does not. I have now resolved this by merging the documents and then printing.
Duncan
A: 

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

xolmc