diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java | 59 | ||||
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java | 3 |
2 files changed, 54 insertions, 8 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java index 5bc748d..b1b1a5a 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java @@ -45,6 +45,7 @@ import com.lowagie.text.Phrase; import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
+import com.lowagie.text.pdf.SubsetLocal;
/**
* This class is the IText implementation of the PDFSignatureObject interface.
@@ -62,7 +63,9 @@ import com.lowagie.text.pdf.PdfPTable; public class PDFSignatureObjectIText implements PDFSignatureObject
{
- /**
+ private static final String SIG_PDFA1_B_VALID = "SIG_PDFA1B_VALID";
+
+/**
* The default font definition
*/
private static Font DEFAULT_FONT = new Font(Font.HELVETICA, 8, Font.NORMAL);
@@ -259,14 +262,33 @@ public class PDFSignatureObjectIText implements PDFSignatureObject */
private Font getCellTrueTypeFont(String fontString) throws PDFDocumentException {
// TODO[tknall-PDF/A]: Remove hardcoded TTF. Impement TTF usage based on configuration.
- logger_.warn("TrueType Fonts are activated. This is only for testing purposes. Deactivate in final release!");
+ // logger_.warn("TrueType Fonts are activated. This is only for testing purposes. Deactivate in final release!");
+
+ float fontSize=8;
+ String fontName = fontString.replaceFirst("TTF:", "");
+ String[] split = fontName.split(",");
+ if(split.length>1)
+ {
+ fontName = split[0].trim();
+ try
+ {
+ fontSize = Float.parseFloat(split[1].trim());
+ }catch (NumberFormatException e)
+ {
+ logger_.error("Unable to parse fontsize:"+fontString);
+ }
+ }
+ logger_.debug("TrueType Font detected:"+fontName +" ("+fontSize+")");
+
try {
Font font = (Font) fontMap_.get(fontString);
+
if (font == null) {
logger_.debug("Font \"" + fontString + "\" not in cache. Instantiating font.");
- String fontPath = SettingsReader.RESOURCES_PATH + "fonts" + File.separator + "DejaVuSansCondensed.ttf";
+ String fontPath = SettingsReader.RESOURCES_PATH + "fonts" + File.separator + fontName;
logger_.debug("Instantiating \"" + fontPath + "\".");
- font = new Font(BaseFont.createFont(fontPath, BaseFont.WINANSI, true), 8);
+
+ font = new Font(BaseFont.createFont(fontPath, BaseFont.WINANSI, true), fontSize);
fontMap_.put(fontString, font);
}
return font;
@@ -297,6 +319,19 @@ public class PDFSignatureObjectIText implements PDFSignatureObject */
private PdfPCell renderCell(Entry abstractCell) throws PDFDocumentException
{
+ boolean pdfaValid =false;
+ try
+ {
+ String profileid = sigObject_.getSignatureTypeDefinition().getType();
+ String pdfa = SettingsReader.getInstance().getSetting("sig_obj." +profileid+".key."+SIG_PDFA1_B_VALID, "default."+SIG_PDFA1_B_VALID, "false");
+ pdfaValid= "true".equalsIgnoreCase(pdfa);
+ SubsetLocal.set(!pdfaValid);
+ logger_.debug("Sign PDF/A complient:"+pdfa);
+ } catch (SettingsException e1)
+ {
+ logger_.error(e1);
+ }
+
PdfPCell pdf_cell = null;
Style cell_style = abstractCell.getStyle();
switch (abstractCell.getType())
@@ -315,9 +350,19 @@ public class PDFSignatureObjectIText implements PDFSignatureObject }
// TODO[tknall-PDF/A]: Deactivate temporary TTF test.
- Font cell_font = getCellFont(font_string);
-// Font cell_font = getCellTrueTypeFont(font_string);
-
+ logger_.debug("using cell font:"+font_string);
+
+ Font cell_font;
+ if(font_string.startsWith("TTF:"))
+ {
+ cell_font = getCellTrueTypeFont(font_string);
+ }
+ else
+ {
+ if(pdfaValid)
+ throw new PDFDocumentException(0,"PDF/A modus requires an embedable true type font");
+ cell_font = getCellFont(font_string);
+ }
Phrase text_phrase = new Phrase(text, cell_font);
pdf_cell = new PdfPCell(text_phrase);
setCellStyle(pdf_cell, cell_style);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java index e3f75f1..530964c 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/SplitStrings.java @@ -35,7 +35,8 @@ public class SplitStrings /**
* The byte used to fill unused bytes in the placeholders.
*/
- public static final byte FILL_BYTE = 0;
+
+ public static final byte FILL_BYTE = ' ';
/**
* The underlying PDF.
|