if (StringUtils.isBlank(destvalue)) {
throw new InstantiationException("You need to choose a destination file");
}
File dest = new File(destvalue);
// we create a reader for a certain document
PdfReader reader = new PdfReader(src.getAbsolutePath());
// we retrieve the total number of pages and the page size
int total = reader.getNumberOfPages();
System.out.println("There are " + total + " pages in the original file.");
Rectangle pageSize = reader.getPageSize(1);
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();
PdfReader reader2 = new PdfReader(new ByteArrayInputStream(tmp.toByteArray()));
PdfStamper stamper = new PdfStamper(reader2, new FileOutputStream(dest));
stamper.setMoreInfo(reader.getInfo());
List<HashMap<String, Object>> outlines = SimpleBookmark.getBookmark(reader);
for (int pageNum=1; pageNum<=total; pageNum++){
int[] range = {pageNum,pageNum};