From 3e46f2b7ba2bf497a8f73d5f2498850f27904ff1 Mon Sep 17 00:00:00 2001 From: Christian Maierhofer Date: Wed, 7 Sep 2016 13:05:29 +0200 Subject: Encoding of unicode characters in signature block is handled by pdfbox now The string to be written to the value field is checked. If one character is not available in the font, the string gets encoded. --- .../lib/impl/stamping/pdfbox2/PDFBoxTable.java | 29 ++++++++++++++++------ .../lib/impl/stamping/pdfbox2/TableDrawUtils.java | 3 ++- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'pdf-as-pdfbox-2/src/main/java') 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 e35e3994..17ee60be 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 @@ -85,8 +85,22 @@ public class PDFBoxTable { case Entry.TYPE_CAPTION: case Entry.TYPE_VALUE: String value = (String) cell.getValue(); - cell.setValue(StringUtils - .convertStringToPDFFormat(value)); + + //Check if the used value font supports all characters in string + PDFont f = null; + try{ + if(valueFont != null){ + f = valueFont.getFont(); + f.getStringWidth(value); + } + }catch(IllegalArgumentException | IOException e){ + if(f!=null){ + logger.warn("Font "+f.getName()+" doesnt support a character in the value "+value); + } + value = StringUtils.convertStringToPDFFormat(value); + cell.setValue(value); + } + break; } } @@ -99,11 +113,6 @@ public class PDFBoxTable { private void initializeStyle(Table abstractTable, PDFBoxTable parent, PDFBOXObject pdfBoxObject) throws IOException { this.table = abstractTable; - try { - normalizeContent(abstractTable); - } catch (PdfAsException e) { - throw new PdfAsWrappedIOException(e); - } if (parent != null) { style = Style.doInherit(abstractTable.getStyle(), parent.style); @@ -148,6 +157,12 @@ public class PDFBoxTable { padding = style.getPadding(); bgColor = style.getBgColor(); + + try { + normalizeContent(abstractTable); + } catch (PdfAsException e) { + throw new PdfAsWrappedIOException(e); + } } public PDFBoxTable(Table abstractTable, PDFBoxTable parent, float fixSize, diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/TableDrawUtils.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/TableDrawUtils.java index aa2a397d..5162b287 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/TableDrawUtils.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox2/TableDrawUtils.java @@ -246,8 +246,9 @@ public class TableDrawUtils { contentStream.moveTextPositionByAmount(tx, (ty - fontSize + (descent * (-1)))); contentStream.appendRawCommands(fontSize + " TL\n"); + for (int k = 0; k < tlines.length; k++) { - contentStream.drawString(tlines[k]); + contentStream.showText(tlines[k]); if (k < tlines.length - 1) { contentStream.appendRawCommands("T*\n"); } -- cgit v1.2.3