aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-05-15 12:46:16 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-05-15 12:46:16 +0200
commit89679faa47dcab8d4ad73c49038f233665f6d44b (patch)
treed3a9d6ef4888f307b6e257a341018c19d45b56be
parent241eeefd4182ce97bc9a9db4031a9b4ffe328ce8 (diff)
downloadpdf-as-4-89679faa47dcab8d4ad73c49038f233665f6d44b.tar.gz
pdf-as-4-89679faa47dcab8d4ad73c49038f233665f6d44b.tar.bz2
pdf-as-4-89679faa47dcab8d4ad73c49038f233665f6d44b.zip
Fixing GIF inclusion
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/ImageUtils.java69
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java2
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java8
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java22
4 files changed, 97 insertions, 4 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/ImageUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/ImageUtils.java
new file mode 100644
index 00000000..c5279100
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/ImageUtils.java
@@ -0,0 +1,69 @@
+package at.gv.egiz.pdfas.common.utils;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.IndexColorModel;
+import java.awt.image.WritableRaster;
+
+public class ImageUtils {
+
+ public static BufferedImage removeAlphaChannel(BufferedImage src) {
+ if (src.getColorModel().hasAlpha())
+ {
+ // extract the alpha information
+ // WritableRaster alphaRaster = src.
+ //ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY),
+ // false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
+ //alpha = new BufferedImage(cm, alphaRaster, false, null);
+ // create a RGB image without alpha
+
+ BufferedImage image = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB);
+ Graphics2D g = image.createGraphics();
+ g.setComposite(AlphaComposite.Src);
+ g.drawImage(src, 0, 0, null);
+ g.dispose();
+ return image;
+ }
+ return src;
+ }
+
+ public static BufferedImage convertRGBAToIndexed(BufferedImage src) {
+ BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(),
+ BufferedImage.TYPE_BYTE_INDEXED);
+ Graphics g = dest.getGraphics();
+ g.setColor(new Color(231, 20, 189));
+ g.fillRect(0, 0, dest.getWidth(), dest.getHeight()); // fill with a
+ // hideous color
+ // and make it
+ // transparent
+ dest = makeTransparent(dest, 0, 0);
+ dest.createGraphics().drawImage(src, 0, 0, null);
+ return dest;
+ }
+
+ public static BufferedImage makeTransparent(BufferedImage image, int x,
+ int y) {
+ ColorModel cm = image.getColorModel();
+ if (!(cm instanceof IndexColorModel))
+ return image; // sorry...
+ IndexColorModel icm = (IndexColorModel) cm;
+ WritableRaster raster = image.getRaster();
+ int pixel = raster.getSample(x, y, 0); // pixel is offset in ICM's
+ // palette
+ int size = icm.getMapSize();
+ byte[] reds = new byte[size];
+ byte[] greens = new byte[size];
+ byte[] blues = new byte[size];
+ icm.getReds(reds);
+ icm.getGreens(greens);
+ icm.getBlues(blues);
+ IndexColorModel icm2 = new IndexColorModel(8, size, reds, greens,
+ blues, pixel);
+ return new BufferedImage(icm2, raster, image.isAlphaPremultiplied(),
+ null);
+ }
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
index ed7033eb..c40704b1 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
@@ -89,7 +89,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
String signatureProfile = parameter.getSignatureProfileId();
if (signatureProfile != null) {
- if (!settings.hasPrefix("sig_obj." + signatureProfile + ".key")) {
+ if (!settings.hasPrefix("sig_obj." + signatureProfile)) {
throw new PdfAsValidationException("error.pdf.sig.09",
signatureProfile);
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java
index 39fe164c..82116474 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java
@@ -28,6 +28,7 @@ import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
+import org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
@@ -42,6 +43,7 @@ import org.slf4j.LoggerFactory;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.common.settings.ISettings;
+import at.gv.egiz.pdfas.common.utils.ImageUtils;
import at.knowcenter.wag.egov.egiz.table.Entry;
import at.knowcenter.wag.egov.egiz.table.Style;
@@ -383,8 +385,14 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
.getWidth();
}
}
+
+ if(img.getAlphaRaster() == null && img.getColorModel().hasAlpha()) {
+ img = ImageUtils.removeAlphaChannel(img);
+ }
PDXObjectImage pdImage = new PDJpeg(template, img);
+
+
ImageObject image = new ImageObject(pdImage, size);
images.put(img_ref, image);
innerFormResources.addXObject(pdImage, "Im");
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 c6d515f9..e76c849e 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
@@ -80,20 +80,36 @@ public class PDFBoxTable {
}
if (style == null) {
- throw new IOException("Failed to determine Table style");
+ throw new IOException("Failed to determine Table style, for table " + abstractTable.getName());
}
String fontString = style.getFont();
String vfontString = style.getValueFont();
+
+ if(fontString == null || vfontString == null) {
+
+ }
+
if (parent != null && style == parent.style) {
font = parent.getFont();
valueFont = parent.getValueFont();
} else {
-
+ if(fontString == null && parent != null && parent.style != null) {
+ fontString = parent.style.getFont();
+ } else if(fontString == null) {
+ throw new IOException("Failed to determine Table font style, for table " + abstractTable.getName());
+ }
+
font = new PDFBoxFont(fontString, settings);
-
+
+ if(vfontString == null && parent != null && parent.style != null) {
+ vfontString = parent.style.getValueFont();
+ } else if(fontString == null) {
+ throw new IOException("Failed to determine value Table font style, for table " + abstractTable.getName());
+ }
+
valueFont = new PDFBoxFont(vfontString, settings);
}
padding = style.getPadding();