Skip to content

Commit

Permalink
Fixing umlauts in form fields (#847)
Browse files Browse the repository at this point in the history
* Fix umlauts in form fields for Helvetica font

* Fix umlauts in form fields for Helvetica font

* Fix umlauts in form fields for Helvetica font
  • Loading branch information
antonleliuk committed Nov 1, 2023
1 parent 2efec11 commit fbc652c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions openpdf/src/main/java/com/lowagie/text/pdf/AcroFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,15 @@ public void decodeGenericDictionary(PdfDictionary merged, BaseField tx) throws D
tx.setTextColor((Color) dab[DA_COLOR]);
}
if (dab[DA_FONT] != null) {
PdfDictionary font = merged.getAsDict(PdfName.DR);
if (font != null) {
font = font.getAsDict(PdfName.FONT);
PdfDictionary dr = merged.getAsDict(PdfName.DR);
if (dr != null) {
PdfDictionary font = dr.getAsDict(PdfName.FONT);
if (font != null) {
PdfObject po = font.get(new PdfName((String) dab[DA_FONT]));
if (po != null && po.type() == PdfObject.INDIRECT) {
PRIndirectReference por = (PRIndirectReference) po;
BaseFont bp = new DocumentFont((PRIndirectReference) po);
adjustFontEncoding(dr, por);
BaseFont bp = new DocumentFont(por);
tx.setFont(bp);
Integer porkey = por.getNumber();
BaseFont porf = extensionFonts.get(porkey);
Expand Down Expand Up @@ -836,6 +837,19 @@ PdfAppearance getAppearance(PdfDictionary merged, String[] values, String fieldN
return app;
}

/** Set font encoding from DR-structure if font doesn't have this info itself */
private void adjustFontEncoding(PdfDictionary dr, PRIndirectReference por) {
PdfDictionary drEncoding = dr.getAsDict(PdfName.ENCODING);
if (drEncoding != null) {
PdfDictionary fontDict = (PdfDictionary) PdfReader.getPdfObject(por);
if (fontDict != null && fontDict.get(PdfName.ENCODING) == null) {
for (PdfName key: drEncoding.getKeys()) {
fontDict.put(PdfName.ENCODING, drEncoding.get(key));
}
}
}
}

PdfAppearance getAppearance(PdfDictionary merged, String text, String fieldName) throws IOException, DocumentException {
String[] valueArr = new String[1];
valueArr[0] = text;
Expand Down

0 comments on commit fbc652c

Please sign in to comment.