@@ -85,10 +85,15 @@ public class PdfPage extends PdfObjectWrapper<PdfDictionary> {
85
85
// TODO This key contains reference to all articles, while this articles could reference to lots of pages.
86
86
// See DEVSIX-191
87
87
PdfName .B ));
88
+
88
89
/**
89
90
* Automatically rotate new content if the page has a rotation ( is disabled by default )
90
91
*/
91
- private boolean ignoreContentRotation = true ;
92
+ private boolean ignorePageRotationForContent = false ;
93
+ /**
94
+ * See {@link #isPageRotationInverseMatrixWritten()}.
95
+ */
96
+ private boolean pageRotationInverseMatrixWritten = false ;
92
97
93
98
protected PdfPage (PdfDictionary pdfObject ) {
94
99
super (pdfObject );
@@ -158,8 +163,9 @@ public int getRotation() {
158
163
}
159
164
}
160
165
161
- public void setRotation (int degAngle ) {
166
+ public PdfPage setRotation (int degAngle ) {
162
167
getPdfObject ().put (PdfName .Rotate , new PdfNumber (degAngle ));
168
+ return this ;
163
169
}
164
170
165
171
public PdfStream getContentStream (int index ) {
@@ -232,9 +238,10 @@ public PdfResources getResources() {
232
238
return this .resources ;
233
239
}
234
240
235
- public void setResources (PdfResources pdfResources ) {
241
+ public PdfPage setResources (PdfResources pdfResources ) {
236
242
getPdfObject ().put (PdfName .Resources , pdfResources .getPdfObject ());
237
243
this .resources = pdfResources ;
244
+ return this ;
238
245
}
239
246
240
247
@@ -416,8 +423,9 @@ public Rectangle getMediaBox() {
416
423
return mediaBox .toRectangle ();
417
424
}
418
425
419
- public void setMediaBox (Rectangle rectangle ) {
426
+ public PdfPage setMediaBox (Rectangle rectangle ) {
420
427
getPdfObject ().put (PdfName .MediaBox , new PdfArray (rectangle ));
428
+ return this ;
421
429
}
422
430
423
431
@@ -433,30 +441,33 @@ public Rectangle getCropBox() {
433
441
return cropBox .toRectangle ();
434
442
}
435
443
436
- public void setCropBox (Rectangle rectangle ) {
444
+ public PdfPage setCropBox (Rectangle rectangle ) {
437
445
getPdfObject ().put (PdfName .CropBox , new PdfArray (rectangle ));
446
+ return this ;
438
447
}
439
448
440
- public void setArtBox (Rectangle rectangle ) {
449
+ public PdfPage setArtBox (Rectangle rectangle ) {
441
450
if (getPdfObject ().getAsRectangle (PdfName .TrimBox ) != null ) {
442
451
getPdfObject ().remove (PdfName .TrimBox );
443
452
Logger logger = LoggerFactory .getLogger (PdfPage .class );
444
453
logger .warn (LogMessageConstant .ONLY_ONE_OF_ARTBOX_OR_TRIMBOX_CAN_EXIST_IN_THE_PAGE );
445
454
}
446
455
getPdfObject ().put (PdfName .ArtBox , new PdfArray (rectangle ));
456
+ return this ;
447
457
}
448
458
449
459
public Rectangle getArtBox () {
450
460
return getPdfObject ().getAsRectangle (PdfName .ArtBox );
451
461
}
452
462
453
- public void setTrimBox (Rectangle rectangle ) {
463
+ public PdfPage setTrimBox (Rectangle rectangle ) {
454
464
if (getPdfObject ().getAsRectangle (PdfName .ArtBox ) != null ) {
455
465
getPdfObject ().remove (PdfName .ArtBox );
456
466
Logger logger = LoggerFactory .getLogger (PdfPage .class );
457
467
logger .warn (LogMessageConstant .ONLY_ONE_OF_ARTBOX_OR_TRIMBOX_CAN_EXIST_IN_THE_PAGE );
458
468
}
459
469
getPdfObject ().put (PdfName .TrimBox , new PdfArray (rectangle ));
470
+ return this ;
460
471
}
461
472
462
473
public Rectangle getTrimBox () {
@@ -634,18 +645,19 @@ public List<PdfOutline> getOutlines(boolean updateOutlines) {
634
645
* @return true - if in case the page has a rotation, then new content will be automatically rotated in the
635
646
* opposite direction. On the rotated page this would look like if new content ignores page rotation.
636
647
*/
637
- public boolean isIgnoreContentRotation () {
638
- return ignoreContentRotation ;
648
+ public boolean isIgnorePageRotationForContent () {
649
+ return ignorePageRotationForContent ;
639
650
}
640
651
641
652
/**
642
653
* If true - defines that in case the page has a rotation, then new content will be automatically rotated in the
643
654
* opposite direction. On the rotated page this would look like if new content ignores page rotation.
644
655
* Default value - {@code false}.
645
- * @param ignoreContentRotation - true to ignore rotation of the new content on the rotated page.
656
+ * @param ignorePageRotationForContent - true to ignore rotation of the new content on the rotated page.
646
657
*/
647
- public void setIgnoreContentRotation (boolean ignoreContentRotation ) {
648
- this .ignoreContentRotation = ignoreContentRotation ;
658
+ public PdfPage setIgnorePageRotationForContent (boolean ignorePageRotationForContent ) {
659
+ this .ignorePageRotationForContent = ignorePageRotationForContent ;
660
+ return this ;
649
661
}
650
662
651
663
/**
@@ -708,6 +720,31 @@ public PdfPage put(PdfName key, PdfObject value) {
708
720
return this ;
709
721
}
710
722
723
+ /**
724
+ * This flag is meaningful for the case, when page rotation is applied and ignorePageRotationForContent
725
+ * is set to true. NOTE: It is needed for the internal usage.
726
+ * <br/><br/>
727
+ * This flag defines if inverse matrix (which rotates content into the opposite direction from page rotation
728
+ * direction in order to give the impression of the not rotated text) is already applied to the page content stream.
729
+ * See {@link #setIgnorePageRotationForContent(boolean)}
730
+ * @return true, if inverse matrix is already applied, false otherwise.
731
+ */
732
+ public boolean isPageRotationInverseMatrixWritten () {
733
+ return pageRotationInverseMatrixWritten ;
734
+ }
735
+
736
+ /**
737
+ * NOTE: For internal usage! Use this method only if you know what you are doing.
738
+ * <br/><br/>
739
+ * This method is called when inverse matrix (which rotates content into the opposite direction from page rotation
740
+ * direction in order to give the impression of the not rotated text) is applied to the page content stream.
741
+ * See {@link #setIgnorePageRotationForContent(boolean)}
742
+ */
743
+ public void setPageRotationInverseMatrixWritten () {
744
+ // this method specifically return void to discourage it's unintended usage
745
+ pageRotationInverseMatrixWritten = true ;
746
+ }
747
+
711
748
@ Override
712
749
protected boolean isWrappedObjectMustBeIndirect () {
713
750
return true ;
0 commit comments