@@ -77,14 +77,25 @@ public class PdfPage extends PdfObjectWrapper<PdfDictionary> {
77
77
private PdfResources resources = null ;
78
78
private int mcid = -1 ;
79
79
PdfPages parentPages ;
80
- private List <PdfName > excludedKeys = new ArrayList <>(Arrays .asList (
80
+ private static final List <PdfName > PAGE_EXCLUDED_KEYS = new ArrayList <>(Arrays .asList (
81
81
PdfName .Parent ,
82
82
PdfName .Annots ,
83
83
PdfName .StructParents ,
84
84
// This key contains reference to all articles, while this articles could reference to lots of pages.
85
85
// See DEVSIX-191
86
86
PdfName .B ));
87
87
88
+ private static final List <PdfName > XOBJECT_EXCLUDED_KEYS ;
89
+
90
+ static {
91
+ XOBJECT_EXCLUDED_KEYS = new ArrayList <>(Arrays .asList (PdfName .MediaBox ,
92
+ PdfName .CropBox ,
93
+ PdfName .TrimBox ,
94
+ PdfName .Contents ));
95
+ XOBJECT_EXCLUDED_KEYS .addAll (PAGE_EXCLUDED_KEYS );
96
+ }
97
+
98
+
88
99
/**
89
100
* Automatically rotate new content if the page has a rotation ( is disabled by default )
90
101
*/
@@ -377,7 +388,7 @@ public PdfPage copyTo(PdfDocument toDocument) {
377
388
* @return copied {@link PdfPage}.
378
389
*/
379
390
public PdfPage copyTo (PdfDocument toDocument , IPdfPageExtraCopier copier ) {
380
- PdfDictionary dictionary = getPdfObject ().copyTo (toDocument , excludedKeys , true );
391
+ PdfDictionary dictionary = getPdfObject ().copyTo (toDocument , PAGE_EXCLUDED_KEYS , true );
381
392
PdfPage page = new PdfPage (dictionary );
382
393
copyInheritedProperties (page , toDocument );
383
394
for (PdfAnnotation annot : getAnnotations ()) {
@@ -418,13 +429,9 @@ public PdfPage copyTo(PdfDocument toDocument, IPdfPageExtraCopier copier) {
418
429
*/
419
430
public PdfFormXObject copyAsFormXObject (PdfDocument toDocument ) throws IOException {
420
431
PdfFormXObject xObject = new PdfFormXObject (getCropBox ());
421
- List <PdfName > excludedKeys = new ArrayList <>(Arrays .asList (PdfName .MediaBox ,
422
- PdfName .CropBox ,
423
- PdfName .Contents )
424
- );
425
- excludedKeys .addAll (this .excludedKeys );
432
+
426
433
for (PdfName key : getPdfObject ().keySet ()) {
427
- if (excludedKeys .contains (key )) {
434
+ if (XOBJECT_EXCLUDED_KEYS .contains (key )) {
428
435
continue ;
429
436
}
430
437
PdfObject obj = getPdfObject ().get (key );
0 commit comments