Skip to content

Commit 54de9ee

Browse files
committed
Get inherited value of Rotate property
DEVSIX-1704
1 parent 01a8816 commit 54de9ee

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfPage.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,16 @@ public Rectangle getPageSizeWithRotation() {
148148
*/
149149
public int getRotation() {
150150
PdfNumber rotate = getPdfObject().getAsNumber(PdfName.Rotate);
151-
151+
int rotateValue = 0;
152152
if (rotate == null) {
153-
return 0;
154-
} else {
155-
int n = rotate.intValue();
156-
n %= 360;
157-
return n < 0 ? n + 360 : n;
153+
initParentPages();
154+
rotate = (PdfNumber) getParentValue(this.parentPages, PdfName.Rotate);
155+
}
156+
if (rotate != null) {
157+
rotateValue = rotate.intValue();
158158
}
159+
rotateValue %= 360;
160+
return rotateValue < 0 ? rotateValue + 360 : rotateValue;
159161
}
160162

161163
/**

kernel/src/test/java/com/itextpdf/kernel/pdf/PdfPagesTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,5 +442,11 @@ public void pageThumbnailTest() throws Exception {
442442
new CompareTool().compareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff");
443443
}
444444

445-
445+
@Test
446+
public void rotationPagesRotationTest() throws IOException {
447+
String filename = "singlePageDocumentWithRotation.pdf";
448+
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + filename));
449+
PdfPage page = pdfDoc.getPage(1);
450+
Assert.assertEquals("Inherited value is invalid", 90, page.getRotation());
451+
}
446452
}

0 commit comments

Comments
 (0)