System.err.println("OddEven needs 3 Arguments.");
System.out.println("Usage: com.lowagie.examples.objects.images.tiff.OddEven odd_file.tif even_file.tif combined_file.pdf");
System.exit(1);
}
try {
RandomAccessFileOrArray odd = new RandomAccessFileOrArray(args[0]);
RandomAccessFileOrArray even = new RandomAccessFileOrArray(args[1]);
LwgImage img = TiffImage.getTiffImage(odd, 1);
LwgDocument document = new LwgDocument(new LwgRectangle(img.getScaledWidth(),
img.getScaledHeight()));
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(args[2]));
document.open();
PdfContentByte cb = writer.getDirectContent();
int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage
.getNumberOfPages(even));
System.out.println("Combining 2 TIFF files into 1 PDF");
for (int c = 0; c < count; ++c) {
try {
LwgImage imgOdd = TiffImage.getTiffImage(odd, c + 1);
LwgImage imgEven = TiffImage.getTiffImage(even, count - c);
document.setPageSize(new LwgRectangle(imgOdd.getScaledWidth(),
imgOdd.getScaledHeight()));
document.newPage();
imgOdd.setAbsolutePosition(0, 0);
cb.addImage(imgOdd);
document.setPageSize(new LwgRectangle(imgEven.getScaledWidth(),
imgEven.getScaledHeight()));
document.newPage();
imgEven.setAbsolutePosition(0, 0);
cb.addImage(imgEven);
} catch (Throwable e) {
System.out.println("Exception page " + (c + 1) + " "
+ e.getMessage());
}
}
odd.close();
even.close();
document.close();
} catch (Throwable e) {
e.printStackTrace();
}
}