Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide PDF/A conform annotations #1084

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public PdfAnnotation(PdfWriter writer, Rectangle rect) {
if (rect != null) {
put(PdfName.RECT, new PdfRectangle(rect));
}
addFKey();
}

/**
Expand All @@ -239,6 +240,7 @@ public PdfAnnotation(PdfWriter writer, float llx, float lly, float urx, float ur
put(PdfName.T, title);
put(PdfName.RECT, new PdfRectangle(llx, lly, urx, ury));
put(PdfName.CONTENTS, content);
addFKey();
}

/**
Expand All @@ -259,6 +261,7 @@ public PdfAnnotation(PdfWriter writer, float llx, float lly, float urx, float ur
put(PdfName.A, action);
put(PdfName.BORDER, new PdfBorderArray(0, 0, 0));
put(PdfName.C, new PdfColor(0x00, 0x00, 0xFF));
addFKey();
}

/**
Expand Down Expand Up @@ -1073,4 +1076,10 @@ public String toString() {
return buf.toString();
}
}

private void addFKey() {
if (writer.isPdfA1()) {
put(PdfName.F, new PdfNumber(FLAGS_PRINT));
}
}
}
4 changes: 4 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,10 @@ public boolean isPdfX() {
return pdfxConformance.isPdfX();
}

public boolean isPdfA1() {
return pdfxConformance.isPdfA1();
}

// [C11] Output intents
/**
* Sets the values of the output intent dictionary. Null values are allowed to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfWriter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.verapdf.core.ModelParsingException;
import org.verapdf.gf.model.GFModelParser;
Expand All @@ -24,10 +25,12 @@
public class PDFValidationTest {

@Test
void validatePDFWithVera() throws Exception {
public void testValidatePDFWithVera() throws Exception {
Document document = new Document(PageSize.A4);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PdfWriter.getInstance(document, byteArrayOutputStream);
PdfWriter pdfWriter = PdfWriter.getInstance(document, byteArrayOutputStream);
pdfWriter.setPDFXConformance(PdfWriter.PDFA1B);
pdfWriter.createXmpMetadata();

try {
document.open();
Expand All @@ -39,7 +42,7 @@ void validatePDFWithVera() throws Exception {
document.close();

// Create a veraPDF validator
PDFAFlavour flavour = PDFAFlavour.PDFA_1_A;
PDFAFlavour flavour = PDFAFlavour.PDFA_1_B;
try (InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
GFModelParser parser = GFModelParser.createModelWithFlavour(inputStream, flavour)) {
PDFAValidator validator = ValidatorFactory.createValidator(flavour, false, 10);
Expand All @@ -56,6 +59,7 @@ void validatePDFWithVera() throws Exception {
}

}
Assertions.assertTrue(result.isCompliant());
}
} catch (ModelParsingException e) {
e.printStackTrace();
Expand Down
Loading