@@ -506,16 +506,7 @@ else if (defaultOverlayPage != null)
506506 PDPage page = inputPDFDocument .getPage (pageNumber - 1 );
507507 if (page .getRotation () != 0 )
508508 {
509- LayoutPage rotatedLayoutPage = rotatedDefaultOverlayPagesMap .get (page .getRotation ());
510- if (rotatedLayoutPage == null )
511- {
512- // createLayoutPage must be called because we can't reuse the COSStream
513- rotatedLayoutPage = createLayoutPage (defaultOverlayDocument .getPage (0 ));
514- int newRotation = (rotatedLayoutPage .overlayRotation - page .getRotation () + 360 ) % 360 ;
515- rotatedLayoutPage .overlayRotation = newRotation ;
516- rotatedDefaultOverlayPagesMap .put (page .getRotation (), rotatedLayoutPage );
517- }
518- return rotatedLayoutPage ;
509+ return createAdjustedLayoutPage (page );
519510 }
520511 }
521512 }
@@ -527,6 +518,20 @@ else if (useAllOverlayPages)
527518 return layoutPage ;
528519 }
529520
521+ private LayoutPage createAdjustedLayoutPage (PDPage page ) throws IOException
522+ {
523+ LayoutPage rotatedLayoutPage = rotatedDefaultOverlayPagesMap .get (page .getRotation ());
524+ if (rotatedLayoutPage == null )
525+ {
526+ // createLayoutPage must be called because we can't reuse the COSStream
527+ rotatedLayoutPage = createLayoutPage (defaultOverlayDocument .getPage (0 ));
528+ int newRotation = (rotatedLayoutPage .overlayRotation - page .getRotation () + 360 ) % 360 ;
529+ rotatedLayoutPage .overlayRotation = newRotation ;
530+ rotatedDefaultOverlayPagesMap .put (page .getRotation (), rotatedLayoutPage );
531+ }
532+ return rotatedLayoutPage ;
533+ }
534+
530535 private PDFormXObject createOverlayFormXObject (LayoutPage layoutPage , PDFCloneUtility cloner )
531536 throws IOException
532537 {
@@ -836,6 +841,5 @@ public void setEvenPageOverlayPDF(PDDocument evenPageOverlayPDF)
836841 public void setAdjustRotation (boolean adjustRotation )
837842 {
838843 this .adjustRotation = adjustRotation ;
839-
840844 }
841845}
0 commit comments