summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/ImageConverter.java23
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java1
-rw-r--r--pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java3
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java58
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/resources/img/fallbackPlaceholder.pngbin0 -> 8189 bytes
5 files changed, 57 insertions, 28 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/ImageConverter.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/ImageConverter.java
index 28fb55a6..83beceff 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/ImageConverter.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/ImageConverter.java
@@ -18,6 +18,7 @@ package at.asit.pdfover.gui;
// Imports
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
import java.awt.image.DirectColorModel;
import java.awt.image.IndexColorModel;
import java.awt.image.WritableRaster;
@@ -147,8 +148,28 @@ public class ImageConverter {
}
}
return data;
+ } else if (bufferedImage.getColorModel() instanceof ComponentColorModel) {
+ ComponentColorModel colorModel = (ComponentColorModel)bufferedImage.getColorModel();
+
+ //ASSUMES: 3 BYTE BGR IMAGE TYPE
+
+ PaletteData palette = new PaletteData(0x0000FF, 0x00FF00,0xFF0000);
+ ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette);
+
+ //This is valid because we are using a 3-byte Data model with no transparent pixels
+ data.transparentPixel = -1;
+
+ WritableRaster raster = bufferedImage.getRaster();
+ int[] pixelArray = new int[3];
+ for (int y = 0; y < data.height; y++) {
+ for (int x = 0; x < data.width; x++) {
+ raster.getPixel(x, y, pixelArray);
+ int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2]));
+ data.setPixel(x, y, pixel);
+ }
+ }
+ return data;
}
return null;
}
-
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java
index 260f49d6..34430abb 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java
@@ -62,7 +62,6 @@ public class PostSLRequestThread implements Runnable {
@Override
public long getLength() {
- // TODO Auto-generated method stub
return this.source.getLength();
}
diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java
index fc9fb346..5f394c1b 100644
--- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java
+++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java
@@ -126,9 +126,8 @@ public abstract class SignatureParameter {
/**
* Gets the Dimension to display the Placeholder
* @return the placeholder dimensions
- * @throws SignatureException thrown if the creation of the placeholdes fails
*/
- public abstract Image getPlaceholder() throws SignatureException;
+ public abstract Image getPlaceholder();
/**
diff --git a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java
index 8668a3f3..3879c434 100644
--- a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java
+++ b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java
@@ -32,7 +32,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.asit.pdfover.signator.SignatureDimension;
-import at.asit.pdfover.signator.SignatureException;
import at.asit.pdfover.signator.SignatureParameter;
import at.asit.pdfover.signator.SignaturePosition;
import at.gv.egiz.pdfas.api.io.DataSource;
@@ -113,53 +112,62 @@ public class PdfAsSignatureParameter extends SignatureParameter {
* @see at.asit.pdfover.signator.SignatureParameter#getPlaceholder()
*/
@Override
- public Image getPlaceholder() throws SignatureException {
+ public Image getPlaceholder() {
- try
- {
+ try {
PDFASHelper.getPdfAs();
-
+
SignatureObject sign_obj = at.knowcenter.wag.egov.egiz.PdfAS
.createSignatureObjectFromType(PDFASSigner.PROFILE_ID);
-
+
sign_obj.fillValues(' ', true, false);
sign_obj.setKZ(BinarySignator_1_1_0.MY_ID);
-
+
float width = getPlaceholderDimension().getWidth();
float height = getPlaceholderDimension().getHeight();
-
+
Table table = sign_obj.getAbstractTable();
-
+
table.getStyle().getBgColor();
-
+
log.info(table.toString());
-
- float[] heights = this.getTableHeights(table, table.getStyle(), height);
-
+
+ float[] heights = this.getTableHeights(table, table.getStyle(),
+ height);
+
log.info("Width: " + width + " Height: " + height);
BufferedImage image = new BufferedImage((int) width, (int) height,
BufferedImage.TYPE_INT_RGB);
Graphics graphic = image.getGraphics();
-
+
graphic.setColor(table.getStyle().getBgColor());
graphic.fillRect(0, 0, (int) width, (int) height);
-
+
graphic.setColor(Color.black);
graphic.drawRect(0, 0, (int) width, (int) height);
-
+
this.drawTable(0, 0, (int) width, (int) height, table,
table.getStyle(), graphic, heights);
-
- save(image, "jpg");
-
+
+ //save(image, "png");
+
return image;
- }
- catch (Exception ex) {
- log.error("Failed to create Placeholder!", ex);
- throw new SignatureException(ex.getMessage());
+ } catch (Exception ex) {
+ try {
+ return ImageIO.read(PdfAsSignatureParameter.class
+ .getResourceAsStream("/img/fallbackPlaceholder.png"));
+ } catch (IOException e) {
+ return new BufferedImage(getPlaceholderDimension().getWidth(), getPlaceholderDimension().getHeight(), BufferedImage.TYPE_INT_RGB);
+ }
}
}
+ /**
+ * used for debugging ..
+ * @param image
+ * @param ext
+ */
+ @SuppressWarnings("unused")
private static void save(BufferedImage image, String ext) {
String fileName = "savingAnImage";
File file = new File(fileName + "." + ext);
@@ -186,7 +194,9 @@ public class PdfAsSignatureParameter extends SignatureParameter {
/**
* extracts the value font
- * @param style the table style
+ *
+ * @param style
+ * the table style
* @return the value font
*/
@SuppressWarnings("unused")
diff --git a/pdf-over-signer/pdf-over-sigpdfas/src/main/resources/img/fallbackPlaceholder.png b/pdf-over-signer/pdf-over-sigpdfas/src/main/resources/img/fallbackPlaceholder.png
new file mode 100644
index 00000000..809e08f5
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas/src/main/resources/img/fallbackPlaceholder.png
Binary files differ