Skip to content

Commit a585dac

Browse files
pavel-alayiText-CI
authored andcommitted
Extract PdfPage coping excluded keys
SUP-3818
1 parent 47f7706 commit a585dac

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,25 @@ public class PdfPage extends PdfObjectWrapper<PdfDictionary> {
7777
private PdfResources resources = null;
7878
private int mcid = -1;
7979
PdfPages parentPages;
80-
private List<PdfName> excludedKeys = new ArrayList<>(Arrays.asList(
80+
private static final List<PdfName> PAGE_EXCLUDED_KEYS = new ArrayList<>(Arrays.asList(
8181
PdfName.Parent,
8282
PdfName.Annots,
8383
PdfName.StructParents,
8484
// This key contains reference to all articles, while this articles could reference to lots of pages.
8585
// See DEVSIX-191
8686
PdfName.B));
8787

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+
8899
/**
89100
* Automatically rotate new content if the page has a rotation ( is disabled by default )
90101
*/
@@ -377,7 +388,7 @@ public PdfPage copyTo(PdfDocument toDocument) {
377388
* @return copied {@link PdfPage}.
378389
*/
379390
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);
381392
PdfPage page = new PdfPage(dictionary);
382393
copyInheritedProperties(page, toDocument);
383394
for (PdfAnnotation annot : getAnnotations()) {
@@ -418,13 +429,9 @@ public PdfPage copyTo(PdfDocument toDocument, IPdfPageExtraCopier copier) {
418429
*/
419430
public PdfFormXObject copyAsFormXObject(PdfDocument toDocument) throws IOException {
420431
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+
426433
for (PdfName key : getPdfObject().keySet()) {
427-
if (excludedKeys.contains(key)) {
434+
if (XOBJECT_EXCLUDED_KEYS.contains(key)) {
428435
continue;
429436
}
430437
PdfObject obj = getPdfObject().get(key);

kernel/src/main/java/com/itextpdf/kernel/pdf/xobject/PdfFormXObject.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public PdfFormXObject(Rectangle bBox) {
8888
*/
8989
public PdfFormXObject(PdfStream pdfStream) {
9090
super(pdfStream);
91+
if (!getPdfObject().containsKey(PdfName.Subtype)) {
92+
getPdfObject().put(PdfName.Subtype, PdfName.Form);
93+
}
9194
}
9295

9396
/**

0 commit comments

Comments
 (0)