Is it possible to print multiple documents at once

4
Hello, I have a question about the possibility to print multiple documents at once. We have created an application that generates every month an invoice (PDF) per client. Now, the customer must print these invoices one by one. Is it possible to create some sort of batch, that provides in the possibility to print al the invoices at once. There are two solutions where I could think of. To create a zip-file with all the relevant invoinces in it which can be printed directly fromout the Windows Explorer after unzipping (Windows functionality) To create one long PDF-file with all the invoices below each other. I prefer solution 2. Is this possible? If so, how?
asked
1 answers
6

You can use this library to merge a bunch of PDF documents.

Code would be something like (taken from the PKN project):

// assume metamodel object is called = SomeDocument;
// docs = input list of SomeDocument, ie. the documents that need to be merged;

import org.apache.pdfbox.util.PDFMergerUtility;

// BEGIN USER CODE
int i = 0;
PDFMergerUtility  mergePdf = new  PDFMergerUtility();
for(i=0; i < this.docs.size(); i++)
{
    SomeDocument file = this.docs.get(i);
    InputStream content = Core.getFileDocumentContent(this.getContext(), file.getMendixObject());
    mergePdf.addSource(content);            
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
mergePdf.setDestinationStream(out);
mergePdf.mergeDocuments();
SomeDocument returnDoc = SomeDocument.create(this.getContext());
Core.storeFileDocumentContent(this.getContext(), returnDoc.getMendixObject(), "Filename" , new ByteArrayInputStream(out.toByteArray()));

out.reset();
this.docs.clear();

return returnDoc.getMendixObject();
// END USER CODE
answered