aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-04-15 16:03:26 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-04-15 16:03:26 +0200
commit53130153222382e2610c227909e446e7ac23827e (patch)
treea3a0ac3c2e286d9d6ec782f77f4c10f621a58736 /pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl
parentb4b272b6af9d1f3c51011a407cdc29f64b812865 (diff)
downloadpdf-as-4-53130153222382e2610c227909e446e7ac23827e.tar.gz
pdf-as-4-53130153222382e2610c227909e446e7ac23827e.tar.bz2
pdf-as-4-53130153222382e2610c227909e446e7ac23827e.zip
Fixed String encoding if CP1252 not applicable, use URL encoding
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java103
1 files changed, 68 insertions, 35 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
index 9cde5fe6..7274cdf2 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
@@ -2,6 +2,7 @@ package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox;
import java.awt.Color;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@@ -10,7 +11,10 @@ import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException;
import at.gv.egiz.pdfas.common.settings.ISettings;
+import at.gv.egiz.pdfas.common.utils.StringUtils;
import at.knowcenter.wag.egov.egiz.table.Entry;
import at.knowcenter.wag.egov.egiz.table.Style;
import at.knowcenter.wag.egov.egiz.table.Table;
@@ -36,10 +40,37 @@ public class PDFBoxTable {
float[] rowHeights;
float[] colWidths;
+ private void normalizeContent(Table abstractTable) throws PdfAsException {
+ try {
+ int rows = abstractTable.getRows().size();
+ for (int i = 0; i < rows; i++) {
+ ArrayList<Entry> row = this.table.getRows().get(i);
+ for (int j = 0; j < row.size(); j++) {
+ Entry cell = (Entry) row.get(j);
+
+ switch (cell.getType()) {
+ case Entry.TYPE_CAPTION:
+ case Entry.TYPE_VALUE:
+ String value = (String) cell.getValue();
+ cell.setValue(StringUtils
+ .convertStringToPDFFormat(value));
+ break;
+ }
+ }
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new PdfAsException("Unsupported Encoding", e);
+ }
+ }
+
private void initializeStyle(Table abstractTable, PDFBoxTable parent)
throws IOException {
this.table = abstractTable;
-
+ try {
+ normalizeContent(abstractTable);
+ } catch(PdfAsException e) {
+ throw new PdfAsWrappedIOException(e);
+ }
if (abstractTable.getStyle() != null) {
style = abstractTable.getStyle();
}
@@ -284,39 +315,41 @@ public class PDFBoxTable {
lines.add(cLineValue.trim());
return lines.toArray(new String[0]);
}
-
-// private String[] breakString(String value, PDFont f, float maxwidth) throws IOException {
-// String[] words = value.split(" ");
-// List<String> lines = new ArrayList<String>();
-// int cLine = 0;
-// String cLineValue = "";
-// for (int i = 0; i < words.length; i++) {
-// String word = words[i];
-// String[] lineBreaks = word.split("\n");
-// if (lineBreaks.length > 1) {
-// for (int j = 0; j < lineBreaks.length; j++) {
-// String subword = lineBreaks[j];
-// // if (cLine + subword.length() > maxline) {
-// lines.add(cLineValue.trim());
-// cLineValue = "";
-// cLine = 0;
-// // }
-// cLineValue += subword + " ";
-// cLine += subword.length();
-// }
-// } else {
-// if (f.getStringWidth(cLineValue + word) > maxwidth && cLineValue.length() != 0) {
-// lines.add(cLineValue.trim());
-// cLineValue = "";
-// cLine = 0;
-// }
-// cLineValue += word + " ";
-// cLine += word.length();
-// }
-// }
-// lines.add(cLineValue.trim());
-// return lines.toArray(new String[0]);
-// }
+
+ // private String[] breakString(String value, PDFont f, float maxwidth)
+ // throws IOException {
+ // String[] words = value.split(" ");
+ // List<String> lines = new ArrayList<String>();
+ // int cLine = 0;
+ // String cLineValue = "";
+ // for (int i = 0; i < words.length; i++) {
+ // String word = words[i];
+ // String[] lineBreaks = word.split("\n");
+ // if (lineBreaks.length > 1) {
+ // for (int j = 0; j < lineBreaks.length; j++) {
+ // String subword = lineBreaks[j];
+ // // if (cLine + subword.length() > maxline) {
+ // lines.add(cLineValue.trim());
+ // cLineValue = "";
+ // cLine = 0;
+ // // }
+ // cLineValue += subword + " ";
+ // cLine += subword.length();
+ // }
+ // } else {
+ // if (f.getStringWidth(cLineValue + word) > maxwidth && cLineValue.length()
+ // != 0) {
+ // lines.add(cLineValue.trim());
+ // cLineValue = "";
+ // cLine = 0;
+ // }
+ // cLineValue += word + " ";
+ // cLine += word.length();
+ // }
+ // }
+ // lines.add(cLineValue.trim());
+ // return lines.toArray(new String[0]);
+ // }
private float getCellHeight(Entry cell, float width) throws IOException {
boolean isValue = true;
@@ -349,7 +382,7 @@ public class PDFBoxTable {
float fheight = c.getFontDescriptor().getFontBoundingBox()
.getHeight()
/ 1000 * fontSize;
-
+
String[] lines = breakString(string, maxcharcount);
cell.setValue(concatLines(lines));
return fheight * lines.length;