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
14 changes: 14 additions & 0 deletions changelogs/4.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ OpenPDF 3.0.x for Java 21 is maintained in the [3.0-java21](https://github.com/L
`Dilithium2`, `Dilithium3` and `Dilithium5` as ML-DSA-44, ML-DSA-65 and ML-DSA-87. CRYSTALS-Dilithium is a different
algorithm, and its signatures were written under the OIDs of ML-DSA. Signing with a Dilithium key, or
`setExternalDigest` with a Dilithium name, now throws. Use an ML-DSA key.
* **PDF/A refuses more content that it does not allow (PR #1814).** Both throw a `PdfXConformanceException`:
* `PdfWriter.addJavaScript` in a PDF/A document. PDF/A does not allow JavaScript.
* In PDF/A-1, a TrueType font with an encoding other than WinAnsi or MacRoman, for example `BaseFont.CP1250`.
PDF/A-1 does not allow the `Differences` array that such a font needs. Use `BaseFont.IDENTITY_H`.
* **`RadioCheckField` keeps the font that is set after `setCheckType` (PR #1814).** Before, the field always went
back to ZapfDingbats when it was created. A check type that is drawn with a font, such as `TYPE_CHECK`, shows the
character of that font.

## 🔒 Security
These fixes are also in [OpenPDF 3.0.7](3.0.7.md).
Expand Down Expand Up @@ -99,6 +106,10 @@ These fixes are also in [OpenPDF 3.0.7](3.0.7.md).
* **Renderer:** `OpenPdfCorePageRenderer` supports the text rendering mode (`Tr`), so that invisible text layers of scanned documents are no longer drawn (PR #1603).

## 🛠 Bug Fixes
* **PDF/A:** Annotations in PDF/A-2 and PDF/A-3 have the `F` key with the print flag, as they already had in PDF/A-1
(PR #1814).
* **PDF/A:** A TrueType font with an encoding other than WinAnsi or MacRoman, such as `BaseFont.CP1250`, has the
base encoding `WinAnsiEncoding`, as PDF/A-2 and PDF/A-3 require (PR #1814).
* **HTML colors:** `WebColors.getRGBColor` now throws an `IllegalArgumentException`, as documented, for an
`rgb()`/`rgba()` value with fewer than three components (for example `rgb()` or `rgb(1,2)`) instead of leaking a
`NoSuchElementException`.
Expand Down Expand Up @@ -132,6 +143,9 @@ These fixes are also in [OpenPDF 3.0.7](3.0.7.md).
collections, and argument checks before `super(...)` in three constructors. `checkstyle.xml` allows `_` as the name
of a lambda parameter and of a pattern variable. The behaviour is not changed (PR #1790).
* **Code Quality:** Fixed a bug reported by SonarCloud in the copy constructor of `RandomAccessFileOrArray` (PR #1689), and one in the soft mask of `OpenPdfCorePageRenderer` (PR #1765).
* **Tests:** veraPDF validates PDF/A documents with the accessible levels 1a, 2a and 3a, bookmarks, a text
annotation, form fields, spot colours, shadings, GIF, PNG and TIFF images, fonts with several encodings, pages of
different sizes with page labels, and an attached file (PR #1814).
* **Code Quality:** Removed reflective calls of the module API from `PdfGraphics2D`. They were written for Java 8 and
had no effect (PR #1785).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,8 @@ public void setName(String name) {
}

private void addFKey() {
if (writer.isPdfA1()) {
// PDF/A requires the F key in all annotations, and the print flag in all that are not a Popup
if (writer != null && writer.isPdfA()) {
put(PdfName.F, new PdfNumber(FLAGS_PRINT));
}
}
Expand Down
24 changes: 24 additions & 0 deletions openpdf-core/src/main/java/org/openpdf/text/pdf/PdfWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1629,8 +1629,10 @@ public void addNamedDestination(String name, int page, PdfDestination dest) {
* runs.
*
* @param js The JavaScript action
* @throws PdfXConformanceException if the document is PDF/A, which does not allow JavaScript
*/
public void addJavaScript(PdfAction js) {
checkNoJavaScriptInPdfA();
pdf.addJavaScript(js);
}

Expand Down Expand Up @@ -1664,11 +1666,19 @@ public void addJavaScript(String code) {
*
* @param name The name of the JS Action in the name tree
* @param js The JavaScript action
* @throws PdfXConformanceException if the document is PDF/A, which does not allow JavaScript
*/
public void addJavaScript(String name, PdfAction js) {
checkNoJavaScriptInPdfA();
pdf.addJavaScript(name, js);
}

private void checkNoJavaScriptInPdfA() {
if (isPdfA()) {
throw new PdfXConformanceException("JavaScript is not allowed in PDF/A.");
}
}

/**
* Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript
* runs.
Expand Down Expand Up @@ -2244,12 +2254,26 @@ FontDetails addSimple(BaseFont bf) {
FontDetails ret = documentFonts.get(bf);
if (ret == null) {
PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_FONT, bf);
checkPdfA1Encoding(bf);
ret = new FontDetails(new PdfName("F" + (fontNumber++)), body.getPdfIndirectReference(), bf);
documentFonts.put(bf, ret);
}
return ret;
}

/**
* PDF/A-1 does not allow a non-symbolic TrueType font with a Differences array (rule 6.3.7), which OpenPDF writes
* for the encodings that are not WinAnsi or MacRoman.
*/
private void checkPdfA1Encoding(BaseFont bf) {
if (isPdfA1() && bf instanceof TrueTypeFont ttf && bf.getFontType() == BaseFont.FONT_TYPE_TT && !ttf.cff
&& !bf.isFontSpecific() && !"Cp1252".equals(bf.getEncoding())
&& !"MacRoman".equals(bf.getEncoding())) {
throw new PdfXConformanceException("PDF/A-1 allows a TrueType font only with the encoding WinAnsi or "
+ "MacRoman. Use BaseFont.IDENTITY_H for " + bf.getPostscriptFontName() + ".");
}
}

void eliminateFontSubset(PdfDictionary fonts) {
for (FontDetails ft : documentFonts.values()) {
if (fonts.get(ft.getFontName()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,9 @@ protected PdfFormField getField(boolean isKid) throws IOException, DocumentExcep
}

field.setValueAsName(checked ? onValue : "Off");
//bugfixed as setting the type wasn't working (also mentioned on the mailinglist on 5th may 2011)
setCheckType(checkType);
// the caption must be the symbol of the check type, but a font that was set after the check type is kept,
// so that an embedded font can be used, as PDF/A requires
setText(typeChars[checkType - 1]);
}
if (text != null) {
field.setMKNormalCaption(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,11 @@ protected PdfDictionary getFontBaseType(PdfIndirectReference fontDescriptor, Str
encoding.equals("Cp1252") ? PdfName.WIN_ANSI_ENCODING : PdfName.MAC_ROMAN_ENCODING);
} else {
PdfDictionary enc = new PdfDictionary(PdfName.ENCODING);
if (!cff) {
// a non-symbolic TrueType font needs a base encoding for its glyphs to be found by name, and
// PDF/A-2 and PDF/A-3 require it (rule 6.2.11.6). All the codes in use are in the differences.
enc.put(PdfName.BASEENCODING, PdfName.WIN_ANSI_ENCODING);
}
PdfArray dif = new PdfArray();
boolean gap = true;
for (int k = firstChar; k <= lastChar; ++k) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class FontSubsetTest {
*/
@Test
void createSubsetPrefixTest() throws Exception {
// not cached: the fixed SecureRandom that is set below must not reach the fonts of other tests
BaseFont font = BaseFont.createFont("LiberationSerif-Regular.ttf", BaseFont.IDENTITY_H,
BaseFont.EMBEDDED, true, getLiberationFontByte(), null);
BaseFont.EMBEDDED, false, getLiberationFontByte(), null);
assertNotEquals(font.createSubsetPrefix(), font.createSubsetPrefix());

byte[] baseSeed = new SecureRandom().generateSeed(512);
Expand Down
Loading
Loading