Skip to content
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
21 changes: 20 additions & 1 deletion changelogs/4.0.1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
<!-- markdownlint-disable MD043 -->
# Release Notes - OpenPDF 4.0.1

## 🌟 New Features & Enhancements

* **Associated files (PR #1806).** `PdfFileSpecification.setAFRelationship(PdfName)` and `associateWith(PdfDictionary)`, `PdfWriter.addAssociatedFile` and `addPageAssociatedFile`, and `PdfStamper.addAssociatedFile` link embedded files to the document, a page or another component, as PDF 2.0 and PDF/A-3 define them, for example the XML of a ZUGFeRD or Factur-X invoice.
* **Tagged annotations (PR #1804, port of #1617).** `PdfStructureElement.addAnnotation(PdfAnnotation)` references a link or another annotation from the structure tree, as PDF/UA requires. The structure tree root gets a `/ParentTreeNextKey` entry.

## 🛠 Bug Fixes

* Fix rendering and extraction when a TrueType glyph index matches a BMP character code (#1793).
* Fix rendering and extraction when a TrueType glyph index matches a BMP character code (PR #1802, fixes #1793).
* **PDF/A-2 and PDF/A-3:** Transparency, images with an alpha channel (`/SMask`) and layers are allowed, as these standards permit. Before, `PdfWriter` rejected them as for PDF/A-1. Fonts in Identity-H encoding no longer write an incomplete `CIDSet`, and the optional content configuration gets a `/Name` and no `/AS` entry (PR #1807).
* **PDF 2.0:** Text strings in UTF-8 are read correctly. `PdfString.toUnicodeString()` decoded them as PDFDocEncoding (PR #1805).
* **Fonts:** `PdfContentByte.showText(GlyphVector)` honors the X positions of the glyphs, so complex scripts such as Devanagari are placed correctly (PR #1804, port of #1618).
* **Tagged PDF:** Structure elements after a marked-content identifier in the kids of an element are written to the structure tree (PR #1804).
* **HTML colors:** `WebColors.getRGBColor` throws an `IllegalArgumentException`, as documented, for an `rgb()` or `rgba()` value with fewer than three components instead of a `NoSuchElementException` (PR #1801).

## 🧹 Maintenance & Refactoring

* **Tests:** `VeraPdfConformanceTest` validates documents created by OpenPDF with veraPDF for PDF/A-1b, PDF/A-2b, PDF/A-2u, PDF/A-3b, PDF/A-3u and PDF/UA-1 (PR #1807).
* **Code Quality:** Codacy no longer checks the changelogs, and the markdownlint rules MD013, MD032 and MD043 are turned off (PR #1803).

## 👥 Contributors

Thanks to everyone who contributed to this release: Amal Saidov, Andreas Røsdal, Lucian Chiriță and Yucheng Du.
13 changes: 9 additions & 4 deletions openpdf-core/src/main/java/org/openpdf/text/pdf/PdfWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,7 @@
* @param erase true to erase, false otherwise
* @since 2.1.2
*/
protected void fillOCProperties(boolean erase) {

Check failure on line 2504 in openpdf-core/src/main/java/org/openpdf/text/pdf/PdfWriter.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AaI4qJbtHolWy25uQexB&open=AaI4qJbtHolWy25uQexB&pullRequest=1807
if (OCProperties == null) {
OCProperties = new PdfOCProperties();
}
Expand Down Expand Up @@ -2532,6 +2532,8 @@
}
PdfDictionary d = new PdfDictionary();
OCProperties.put(PdfName.D, d);
// PDF/A-2 and PDF/A-3 (rule 6.9) require a name for the optional content configuration
d.put(PdfName.NAME, new PdfString("Default"));
d.put(PdfName.ORDER, order);
PdfArray gr = new PdfArray();
for (PdfOCG o : documentOCG) {
Expand All @@ -2549,10 +2551,13 @@
if (OCGLocked != null && !OCGLocked.isEmpty()) {
d.put(PdfName.LOCKED, OCGLocked);
}
addASEvent(PdfName.VIEW, PdfName.ZOOM);
addASEvent(PdfName.VIEW, PdfName.VIEW);
addASEvent(PdfName.PRINT, PdfName.PRINT);
addASEvent(PdfName.EXPORT, PdfName.EXPORT);
// PDF/A-2 and PDF/A-3 (rule 6.9) do not allow the AS key in the optional content configuration
if (!isPdfA()) {
addASEvent(PdfName.VIEW, PdfName.ZOOM);
addASEvent(PdfName.VIEW, PdfName.VIEW);
addASEvent(PdfName.PRINT, PdfName.PRINT);
addASEvent(PdfName.EXPORT, PdfName.EXPORT);
}
d.put(PdfName.LISTMODE, PdfName.VISIBLEPAGES);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ private PdfIndirectReference writeCidSet(PdfWriter writer, int[][] metrics) thro
&& writer.getPDFXConformance() != PdfWriter.PDFA1B) {
return null;
}
// PDF/A-2 and PDF/A-3 (rule 6.2.11.4.2) require a CIDSet to identify all CIDs of the font program, also of a
// subset. The CIDSet is optional there, so it is left out.
if (writer.isPdfA2() || writer.isPdfA3()) {
return null;
}
PdfStream stream;
if (metrics.length == 0) {
stream = new PdfStream(new byte[]{(byte) 0x80});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
}
case PDFXKEY_IMAGE -> {
PdfImage image = (PdfImage) obj1;
if (image.get(PdfName.SMASK) != null) {
if (image.get(PdfName.SMASK) != null && !allowsTransparency(writer)) {
throw new PdfXConformanceException(
MessageLocalization.getComposedMessage("the.smask.key.is.not.allowed.in.images"));
}
Expand All @@ -194,6 +194,9 @@
}
}
case PDFXKEY_GSTATE -> {
if (allowsTransparency(writer)) {
return;
}
PdfDictionary gs = (PdfDictionary) obj1;
PdfObject obj = gs.get(PdfName.BM);
if (obj != null && !PdfGState.BM_NORMAL.equals(obj) && !PdfGState.BM_COMPATIBLE.equals(obj)) {
Expand All @@ -216,11 +219,36 @@
}
}
case PDFXKEY_LAYER -> {
throw new PdfXConformanceException(MessageLocalization.getComposedMessage("layers.are.not.allowed"));
if (!allowsOptionalContent(writer)) {
throw new PdfXConformanceException(
MessageLocalization.getComposedMessage("layers.are.not.allowed"));
}

Check warning on line 225 in openpdf-core/src/main/java/org/openpdf/text/pdf/internal/PdfXConformanceImp.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this "if" statement with a pattern match guard.

See more on https://sonarcloud.io/project/issues?id=LibrePDF_OpenPDF&issues=AaI4qJcNHolWy25uQexC&open=AaI4qJcNHolWy25uQexC&pullRequest=1807
}
}
}

/**
* Tells if the conformance level of the writer allows transparency: soft masks, constant alpha and blend modes.
* PDF/A-2 and PDF/A-3 allow it, PDF/A-1, PDF/X-1a and PDF/X-3 do not.
*
* @param writer the writer
* @return {@code true} if transparency is allowed
*/
private static boolean allowsTransparency(PdfWriter writer) {
return writer.isPdfA2() || writer.isPdfA3();
}

/**
* Tells if the conformance level of the writer allows optional content (layers). PDF/A-2 and PDF/A-3 allow it,
* PDF/A-1, PDF/X-1a and PDF/X-3 do not.
*
* @param writer the writer
* @return {@code true} if optional content is allowed
*/
private static boolean allowsOptionalContent(PdfWriter writer) {
return writer.isPdfA2() || writer.isPdfA3();
}

/**
* @see org.openpdf.text.pdf.interfaces.PdfXConformance#getPDFXConformance()
*/
Expand Down
Loading
Loading