PageRotation[] rotations = inputCommand.getRotations();
if (rotations != null && rotations.length > 0) {
if (rotations.length > 1) {
for (int i = 0; i < rotations.length; i++) {
if (pdfNumberOfPages >= rotations[i].getPageNumber() && rotations[i].getPageNumber() > 0) {
PdfDictionary dictionary = rotationReader.getPageN(rotations[i].getPageNumber());
int rotation = (rotations[i].getDegrees() + rotationReader.getPageRotation(rotations[i]
.getPageNumber())) % 360;
dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
} else {
LOG.warn("Rotation for page " + rotations[i].getPageNumber() + " ignored.");
}
}
} else {
// rotate all
if (rotations[0].getType() == PageRotation.ALL_PAGES) {
int pageRotation = rotations[0].getDegrees();
for (int i = 1; i <= pdfNumberOfPages; i++) {
PdfDictionary dictionary = rotationReader.getPageN(i);
int rotation = (pageRotation + rotationReader.getPageRotation(i)) % 360;
dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
}
} else if (rotations[0].getType() == PageRotation.SINGLE_PAGE) {
// single page rotation
if (pdfNumberOfPages >= rotations[0].getPageNumber() && rotations[0].getPageNumber() > 0) {
PdfDictionary dictionary = rotationReader.getPageN(rotations[0].getPageNumber());
int rotation = (rotations[0].getDegrees() + rotationReader.getPageRotation(rotations[0]
.getPageNumber())) % 360;
dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
} else {
LOG.warn("Rotation for page " + rotations[0].getPageNumber() + " ignored.");
}
} else if (rotations[0].getType() == PageRotation.ODD_PAGES) {
// odd pages rotation
int pageRotation = rotations[0].getDegrees();
for (int i = 1; i <= pdfNumberOfPages; i = i + 2) {
PdfDictionary dictionary = rotationReader.getPageN(i);
int rotation = (pageRotation + rotationReader.getPageRotation(i)) % 360;
dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
}
} else if (rotations[0].getType() == PageRotation.EVEN_PAGES) {
// even pages rotation
int pageRotation = rotations[0].getDegrees();
for (int i = 2; i <= pdfNumberOfPages; i = i + 2) {
PdfDictionary dictionary = rotationReader.getPageN(i);
int rotation = (pageRotation + rotationReader.getPageRotation(i)) % 360;
dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
}
} else {
LOG.warn("Unable to find the rotation type. " + rotations[0]);
}
}