Rectangle newSize = new Rectangle(pageSize.getWidth()*2, pageSize.getHeight());
// step 1: creation of a document-object
Document document = new Document(newSize, 0, 0, 0, 0);
// step 2: we create a writer that listens to the document
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, tmp);
writer.setFullCompression();
// step 3: we open the document
document.open();
// step 4: adding the content
PdfContentByte cb = writer.getDirectContent();
PdfImportedPage page;
float offsetX;
for (int p = 1; p <= total; p++) {
offsetX = 0;
if (p % 2 != 0) {
document.newPage();
} else {
offsetX = pageSize.getWidth();
}
page = writer.getImportedPage(reader, p);
cb.addTemplate(page, offsetX, 0);
}
// step 5: we close the document
document.close();