diff options
author | Christian Maierhofer <cmaierhofer@iaik.tugraz.at> | 2016-06-21 15:35:47 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2016-08-17 16:49:55 +0200 |
commit | 998859c70f4ce4e1ea6924b053c231351dfe5703 (patch) | |
tree | eb85e2ab7b6f0eb0350d1f8d4a110cd80293ee7d /pdf-as-pdfbox-2/src/main/java | |
parent | 464c44c367f32f8e7624a6b3ed3474c95a69d6fa (diff) | |
download | pdf-as-4-998859c70f4ce4e1ea6924b053c231351dfe5703.tar.gz pdf-as-4-998859c70f4ce4e1ea6924b053c231351dfe5703.tar.bz2 pdf-as-4-998859c70f4ce4e1ea6924b053c231351dfe5703.zip |
nbspace was not recognized by pdfbox' internal fonts
Diffstat (limited to 'pdf-as-pdfbox-2/src/main/java')
-rw-r--r-- | pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFBoxTable.java | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFBoxTable.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFBoxTable.java index 415e1665..e35e3994 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFBoxTable.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/PDFBoxTable.java @@ -49,6 +49,8 @@ public class PDFBoxTable { private static final Logger logger = LoggerFactory .getLogger(PDFBoxTable.class); + + private static final String NBSPACE = '\u00A0'+""; Table table; Style style; @@ -331,17 +333,19 @@ public class PDFBoxTable { string = ""; cell.setValue(string); } - if (string.contains("\n")) { + if (string.contains(NBSPACE) || string.contains("\n")) { float maxWidth = 0; + string = string.replace(NBSPACE, " "); String[] lines = string.split("\n"); + for (int i = 0; i < lines.length; i++) { float w = c.getStringWidth(lines[i]) / 1000 * fontSize; if (maxWidth < w) { maxWidth = w; } } - return maxWidth; - } else { + } + else{ return c.getStringWidth(string) / 1000 * fontSize; } case Entry.TYPE_IMAGE: @@ -399,6 +403,8 @@ public class PDFBoxTable { } // } String tmpLine = cLineValue + subword; + tmpLine = tmpLine.replace(NBSPACE, " "); + float size = font.getStringWidth(tmpLine) / 1000.0f * fontSize; if (size > maxwidth && cLineValue.length() != 0) { @@ -409,6 +415,8 @@ public class PDFBoxTable { } } else { String tmpLine = cLineValue + word; + tmpLine = tmpLine.replace(NBSPACE, " "); + float size = font.getStringWidth(tmpLine) / 1000.0f * fontSize; if (size > maxwidth && cLineValue.length() != 0) { lines.add(cLineValue.trim()); @@ -418,6 +426,9 @@ public class PDFBoxTable { } } lines.add(cLineValue.trim()); + for(int i=0;i<lines.size();i++){ + lines.set(i, lines.get(i).replace(NBSPACE, " ")); + } return lines.toArray(new String[0]); } |