Skip to content

Commit 2204b35

Browse files
committed
Refactor PDF conformance hierarchy
* Provide new PdfConformance class which store both PDF/A and PDF/UA * Get rid of "level" word everywhere * Always return not null conformance isntance from PdfDocument * Read conformance from PdfReader even for usual PdfDocument's DEVSIX-8571
1 parent 239e843 commit 2204b35

File tree

119 files changed

+1367
-1162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1367
-1162
lines changed

forms/src/main/java/com/itextpdf/forms/fields/AbstractPdfFormField.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ This file is part of the iText (R) project.
3131
import com.itextpdf.kernel.colors.DeviceGray;
3232
import com.itextpdf.kernel.colors.DeviceRgb;
3333
import com.itextpdf.kernel.font.PdfFont;
34-
import com.itextpdf.kernel.pdf.IConformanceLevel;
35-
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
34+
import com.itextpdf.kernel.pdf.PdfConformance;
3635
import com.itextpdf.kernel.pdf.PdfDictionary;
3736
import com.itextpdf.kernel.pdf.PdfDocument;
3837
import com.itextpdf.kernel.pdf.PdfName;
@@ -84,7 +83,7 @@ public abstract class AbstractPdfFormField extends PdfObjectWrapper<PdfDictionar
8483
protected float fontSize = -1;
8584
protected Color color;
8685

87-
protected IConformanceLevel pdfConformanceLevel;
86+
protected PdfConformance pdfConformance;
8887

8988
/**
9089
* Parent form field.
@@ -225,12 +224,12 @@ public Color getColor() {
225224
}
226225

227226
/**
228-
* Gets the declared conformance level.
227+
* Gets the declared conformance.
229228
*
230-
* @return the {@link IConformanceLevel}
229+
* @return the {@link PdfConformance}
231230
*/
232-
public IConformanceLevel getPdfConformanceLevel() {
233-
return pdfConformanceLevel == null && parent != null ? parent.getPdfConformanceLevel() : pdfConformanceLevel;
231+
public PdfConformance getPdfConformance() {
232+
return pdfConformance == null && parent != null ? parent.getPdfConformance() : pdfConformance;
234233
}
235234

236235
/**

forms/src/main/java/com/itextpdf/forms/fields/CheckBoxFormFieldBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public PdfButtonFormField createCheckBox() {
7878
} else {
7979
PdfWidgetAnnotation annotation = new PdfWidgetAnnotation(getWidgetRectangle());
8080
annotation.setAppearanceState(new PdfName(PdfFormAnnotation.OFF_STATE_VALUE));
81-
if (getConformanceLevel() != null) {
81+
if (getConformance() != null && getConformance().isPdfAOrUa()) {
8282
annotation.setFlag(PdfAnnotation.PRINT);
8383
}
8484
check = PdfFormCreator.createButtonFormField(annotation, getDocument());
8585
}
8686
check.disableFieldRegeneration();
87-
check.pdfConformanceLevel = getConformanceLevel();
87+
check.pdfConformance = getConformance();
8888
check.setCheckType(checkType);
8989
check.setFieldName(getFormFieldName());
9090
// the default behavior is to automatically calculate the fontsize

forms/src/main/java/com/itextpdf/forms/fields/ChoiceFormFieldBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ private PdfChoiceFormField createChoice(int flags) {
123123
field = PdfFormCreator.createChoiceFormField(getDocument());
124124
} else {
125125
annotation = new PdfWidgetAnnotation(getWidgetRectangle());
126-
if (null != getConformanceLevel()) {
126+
if (null != getConformance() && getConformance().isPdfAOrUa()) {
127127
annotation.setFlag(PdfAnnotation.PRINT);
128128
}
129129
field = PdfFormCreator.createChoiceFormField(annotation, getDocument());
130130
}
131131
field.disableFieldRegeneration();
132-
field.pdfConformanceLevel = getConformanceLevel();
132+
field.pdfConformance = getConformance();
133133
if (this.getFont() != null) {
134134
field.setFont(this.getFont());
135135
}

forms/src/main/java/com/itextpdf/forms/fields/FormFieldBuilder.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.forms.fields;
2424

25-
import com.itextpdf.kernel.pdf.IConformanceLevel;
26-
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
25+
import com.itextpdf.kernel.pdf.PdfConformance;
2726
import com.itextpdf.kernel.pdf.PdfDocument;
2827

2928
/**
@@ -42,9 +41,9 @@ public abstract class FormFieldBuilder<T extends FormFieldBuilder<T>> {
4241
*/
4342
private final String formFieldName;
4443
/**
45-
* Conformance level of the form field.
44+
* Conformance of the form field.
4645
*/
47-
private IConformanceLevel conformanceLevel = null;
46+
private PdfConformance conformance = null;
4847

4948
/**
5049
* Creates builder for {@link PdfFormField} creation.
@@ -56,7 +55,7 @@ protected FormFieldBuilder(PdfDocument document, String formFieldName) {
5655
this.document = document;
5756
this.formFieldName = formFieldName;
5857
if (document != null) {
59-
this.conformanceLevel = document.getConformanceLevel();
58+
this.conformance = document.getConformance();
6059
}
6160
}
6261

@@ -79,23 +78,23 @@ public String getFormFieldName() {
7978
}
8079

8180
/**
82-
* Gets conformance level for form field creation.
81+
* Gets conformance for form field creation.
8382
*
84-
* @return instance of {@link IConformanceLevel} to be used for form field creation
83+
* @return instance of {@link PdfConformance} to be used for form field creation
8584
*/
86-
public IConformanceLevel getConformanceLevel() {
87-
return conformanceLevel;
85+
public PdfConformance getConformance() {
86+
return conformance;
8887
}
8988

9089
/**
91-
* Sets conformance level for form field creation.
90+
* Sets conformance for form field creation.
9291
*
93-
* @param conformanceLevel Instance of {@link IConformanceLevel} to be used for form field creation.
92+
* @param conformance Instance of {@link PdfConformance} to be used for form field creation.
9493
*
9594
* @return this builder
9695
*/
97-
public T setConformanceLevel(IConformanceLevel conformanceLevel) {
98-
this.conformanceLevel = conformanceLevel;
96+
public T setConformance(PdfConformance conformance) {
97+
this.conformance = conformance;
9998
return getThis();
10099
}
101100

forms/src/main/java/com/itextpdf/forms/fields/NonTerminalFormFieldBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public NonTerminalFormFieldBuilder(PdfDocument document, String formFieldName) {
4646
*/
4747
public PdfFormField createNonTerminalFormField() {
4848
PdfFormField field = PdfFormCreator.createFormField(getDocument());
49-
field.pdfConformanceLevel = getConformanceLevel();
49+
field.pdfConformance = getConformance();
5050
field.setFieldName(getFormFieldName());
5151
return field;
5252
}

forms/src/main/java/com/itextpdf/forms/fields/PdfFormAnnotation.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ public static PdfFormAnnotation makeFormAnnotation(PdfObject pdfObject, PdfDocum
161161
}
162162
field.makeIndirect(document);
163163

164-
if (document != null && document.getReader() != null
165-
&& document.getReader().getPdfAConformanceLevel() != null) {
166-
field.pdfConformanceLevel = document.getReader().getPdfAConformanceLevel();
164+
if (document != null) {
165+
field.pdfConformance = document.getConformance();
167166
}
168167

169168
return field;
@@ -1005,7 +1004,7 @@ protected void drawCheckBoxAndSaveAppearance(String onStateName) {
10051004
final Canvas canvasOff = new Canvas(xObjectOff, getDocument());
10061005
setMetaInfoToCanvas(canvasOff);
10071006
canvasOff.add(formFieldElement);
1008-
if (getPdfConformanceLevel() == null) {
1007+
if (getPdfConformance() == null || !getPdfConformance().isPdfAOrUa()) {
10091008
xObjectOff.getResources().addFont(getDocument(), getFont());
10101009
}
10111010
normalAppearance.put(new PdfName(OFF_STATE_VALUE), xObjectOff.getPdfObject());
@@ -1225,7 +1224,7 @@ private void createCheckBox() {
12251224

12261225
formFieldElement.setProperty(Property.FONT_SIZE, UnitValue.createPointValue(getFontSize()));
12271226
setModelElementProperties(getRect(getPdfObject()));
1228-
((CheckBox) formFieldElement).setPdfConformanceLevel(getPdfConformanceLevel());
1227+
((CheckBox) formFieldElement).setPdfConformance(getPdfConformance());
12291228
((CheckBox) formFieldElement).setCheckBoxType(parent.checkType.getValue());
12301229
}
12311230

forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,8 @@ public static PdfFormField makeFormField(PdfObject pdfObject, PdfDocument docume
255255
}
256256
field.makeIndirect(document);
257257

258-
if (document != null && document.getReader() != null &&
259-
document.getReader().getPdfAConformanceLevel() != null) {
260-
field.pdfConformanceLevel = document.getReader().getPdfAConformanceLevel();
258+
if (document != null) {
259+
field.pdfConformance = document.getConformance();
261260
}
262261

263262
return field;
@@ -1068,7 +1067,7 @@ public PdfFormField setCheckType(CheckBoxType checkType) {
10681067
checkType = CheckBoxType.CROSS;
10691068
}
10701069
this.checkType = new NullableContainer<>(checkType);
1071-
if (getPdfConformanceLevel() != null) {
1070+
if (getPdfConformance() != null && getPdfConformance().isPdfAOrUa()) {
10721071
return this;
10731072
}
10741073
try {

forms/src/main/java/com/itextpdf/forms/fields/PushButtonFormFieldBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ public PdfButtonFormField createPushButton() {
8181
} else {
8282
annotation = new PdfWidgetAnnotation(getWidgetRectangle());
8383
field = PdfFormCreator.createButtonFormField(annotation, getDocument());
84-
if (null != getConformanceLevel()) {
84+
if (null != getConformance() && getConformance().isPdfAOrUa()) {
8585
annotation.setFlag(PdfAnnotation.PRINT);
8686
}
8787
}
8888
field.disableFieldRegeneration();
8989
if (this.getFont() != null) {
9090
field.setFont(this.getFont());
9191
}
92-
field.pdfConformanceLevel = getConformanceLevel();
92+
field.pdfConformance = getConformance();
9393
field.setPushButton(true);
9494
field.setFieldName(getFormFieldName());
9595
field.text = caption;

forms/src/main/java/com/itextpdf/forms/fields/RadioFormFieldBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public RadioFormFieldBuilder(PdfDocument document, String radioGroupFormFieldNam
5454
public PdfButtonFormField createRadioGroup() {
5555
PdfButtonFormField radioGroup = PdfFormCreator.createButtonFormField(getDocument());
5656
radioGroup.disableFieldRegeneration();
57-
radioGroup.pdfConformanceLevel = getConformanceLevel();
57+
radioGroup.pdfConformance = getConformance();
5858
radioGroup.setFieldName(getFormFieldName());
5959
radioGroup.setFieldFlags(PdfButtonFormField.FF_RADIO);
6060
radioGroup.enableFieldRegeneration();
@@ -84,12 +84,12 @@ public PdfFormAnnotation createRadioButton(String appearanceName, Rectangle rect
8484
final PdfName appearancePdfName = new PdfName(appearanceName);
8585
final PdfWidgetAnnotation annotation = new PdfWidgetAnnotation(widgetRectangle);
8686
annotation.setAppearanceState(appearancePdfName);
87-
if (getConformanceLevel() != null) {
87+
if (getConformance() != null && getConformance().isPdfAOrUa()) {
8888
annotation.setFlag(PdfAnnotation.PRINT);
8989
}
9090
PdfFormAnnotation radio = PdfFormCreator.createFormAnnotation(annotation, getDocument());
9191
setPageToField(radio);
92-
radio.pdfConformanceLevel = getConformanceLevel();
92+
radio.pdfConformance = getConformance();
9393
return radio;
9494
}
9595

forms/src/main/java/com/itextpdf/forms/fields/SignatureFormFieldBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public PdfSignatureFormField createSignature() {
5252
signatureFormField = PdfFormCreator.createSignatureFormField(getDocument());
5353
} else {
5454
PdfWidgetAnnotation annotation = new PdfWidgetAnnotation(getWidgetRectangle());
55-
if (getConformanceLevel() != null) {
55+
if (getConformance() != null && getConformance().isPdfAOrUa()) {
5656
annotation.setFlag(PdfAnnotation.PRINT);
5757
}
5858
signatureFormField = PdfFormCreator.createSignatureFormField(annotation, getDocument());
@@ -63,7 +63,7 @@ public PdfSignatureFormField createSignature() {
6363
if (getFont() != null) {
6464
signatureFormField.font = getFont();
6565
}
66-
signatureFormField.pdfConformanceLevel = getConformanceLevel();
66+
signatureFormField.pdfConformance = getConformance();
6767
signatureFormField.setFieldName(getFormFieldName());
6868
return signatureFormField;
6969
}

0 commit comments

Comments
 (0)