aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/ImageUtils.java6
-rw-r--r--pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java5
-rw-r--r--pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java104
-rw-r--r--pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java11
4 files changed, 79 insertions, 47 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
index ab087f2c..39ebd3e0 100644
--- 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
@@ -57,7 +57,7 @@ public class ImageUtils {
.getLogger(ImageUtils.class);
public static BufferedImage removeAlphaChannel(BufferedImage src) {
- if (src.getColorModel().hasAlpha()) {
+ //if (src.getColorModel().hasAlpha()) {
BufferedImage image = new BufferedImage(src.getWidth(),
src.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
@@ -65,8 +65,8 @@ public class ImageUtils {
g.drawImage(src, 0, 0, null);
g.dispose();
return image;
- }
- return src;
+ //}
+ //return src;
/*
* BufferedImage rgbImage = new BufferedImage(src.getWidth(),
* src.getHeight(), BufferedImage.TYPE_3BYTE_BGR); for (int x = 0; x <
diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
index 45dfbcc5..d1337ce2 100644
--- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
+++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
@@ -316,7 +316,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties(
pdfObject.getStatus().getSettings(), pdfObject,
(PdfBoxVisualObject) visualObject,
- positioningInstruction);
+ positioningInstruction, signatureProfileSettings);
properties.buildSignature();
@@ -665,7 +665,8 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties(
pdfObject.getStatus().getSettings(), pdfObject,
- (PdfBoxVisualObject) visualObject, positioningInstruction);
+ (PdfBoxVisualObject) visualObject, positioningInstruction,
+ signatureProfileSettings);
properties.buildSignature();
PDDocument visualDoc = PDDocument.load(properties
diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java
index d0b71fd0..5c6610fe 100644
--- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java
+++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java
@@ -23,6 +23,7 @@
******************************************************************************/
package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox;
+import java.awt.Transparency;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
@@ -70,7 +71,8 @@ import at.gv.egiz.pdfas.common.settings.ISettings;
import at.gv.egiz.pdfas.common.utils.ImageUtils;
import at.knowcenter.wag.egov.egiz.table.Entry;
-public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements IDGenerator {
+public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
+ IDGenerator {
private static final Logger logger = LoggerFactory
.getLogger(PDFAsVisualSignatureBuilder.class);
@@ -126,12 +128,12 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.reset();
return Hex.encodeHexString(md.digest(value.getBytes("UTF-8")));
- } catch(Throwable e) {
+ } catch (Throwable e) {
logger.warn("Failed to generate ID for Image using value", e);
return value;
}
}
-
+
private void readTableResources(PDFBoxTable table, PDDocument template)
throws PdfAsException, IOException {
@@ -181,7 +183,8 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
String img_value = (String) cell.getValue();
String img_ref = createHashedId(img_value);
if (!images.containsKey(img_ref)) {
- BufferedImage img = ImageUtils.getImage(img_value, settings);
+ BufferedImage img = ImageUtils.getImage(img_value,
+ settings);
float width = colsSizes[j];
float height = table.getRowHeights()[i] + padding * 2;
@@ -215,15 +218,20 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
.floor((double) (scaleFactor * origWidth));
iheight = (float) Math
.floor((double) (scaleFactor * origHeight));
-
+
logger.debug("Scaling image to: " + iwidth + " x "
+ iheight);
- if (img.getAlphaRaster() == null &&
- img.getColorModel().hasAlpha()) {
- img = ImageUtils.removeAlphaChannel(img);
+ if (this.designer.properties
+ .getSignatureProfileSettings().isPDFA()) {
+ //img = ImageUtils.removeAlphaChannel(img);
+ } else {
+ if (img.getAlphaRaster() == null
+ && img.getColorModel().hasAlpha()) {
+ img = ImageUtils.removeAlphaChannel(img);
+ }
}
- //img = ImageUtils.convertRGBAToIndexed(img);
+ // img = ImageUtils.convertRGBAToIndexed(img);
PDXObjectImage pdImage = new PDPixelMap(template, img);
@@ -240,18 +248,19 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
}
}
- public void createInnerFormStreamPdfAs(PDDocument template) throws PdfAsException {
+ public void createInnerFormStreamPdfAs(PDDocument template)
+ throws PdfAsException {
try {
// Hint we have to create all PDXObjectImages before creating the
// PDPageContentStream
// only PDFbox developers know why ...
- //if (getStructure().getPage().getResources() != null) {
- // innerFormResources = getStructure().getPage().getResources();
- //} else {
- innerFormResources = new PDResources();
- getStructure().getPage().setResources(innerFormResources);
- //}
+ // if (getStructure().getPage().getResources() != null) {
+ // innerFormResources = getStructure().getPage().getResources();
+ // } else {
+ innerFormResources = new PDResources();
+ getStructure().getPage().setResources(innerFormResources);
+ // }
readTableResources(properties.getMainTable(), template);
PDPageContentStream stream = new PDPageContentStream(template,
@@ -268,7 +277,8 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
} catch (Throwable e) {
logger.warn("Failed to create visual signature block", e);
- throw new PdfAsException("Failed to create visual signature block", e);
+ throw new PdfAsException("Failed to create visual signature block",
+ e);
}
}
@@ -313,15 +323,15 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
String holderFormComment = "q " + m00 + " " + m10 + " " + m01 + " "
+ m11 + " " + m02 + " " + m12 + " cm /" + innerFormName
+ " Do Q \n";
-
+
logger.debug("Holder Form Stream: " + holderFormComment);
-
+
// String innerFormComment = "q 1 0 0 1 0 0 cm /" + imageObjectName +
// " Do Q\n";
String innerFormComment = getStructure().getInnterFormStream()
.getInputStreamAsString();
- //logger.debug("Inner Form Stream: " + innerFormComment);
+ // logger.debug("Inner Form Stream: " + innerFormComment);
// appendRawCommands(getStructure().getInnterFormStream().createOutputStream(),
// getStructure().getInnterFormStream().getInputStreamAsString());
@@ -398,55 +408,67 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
Point2D llSrc = new Point2D.Float();
llSrc.setLocation(properties.getxAxis(), properties.getPageHeight()
- properties.getyAxis() - properties.getHeight());
-
+
rect.setUpperRightX((float) upSrc.getX());
rect.setUpperRightY((float) upSrc.getY());
rect.setLowerLeftY((float) llSrc.getY());
rect.setLowerLeftX((float) llSrc.getX());
logger.debug("orig rectangle of signature has been created: {}",
rect.toString());
-
+
AffineTransform transform = new AffineTransform();
transform.setToIdentity();
if (degrees % 360 != 0) {
transform.setToRotation(Math.toRadians(degrees), llSrc.getX(),
llSrc.getY());
}
-
-
+
Point2D upDst = new Point2D.Float();
transform.transform(upSrc, upDst);
Point2D llDst = new Point2D.Float();
transform.transform(llSrc, llDst);
-
+
float xPos = properties.getxAxis();
float yPos = properties.getPageHeight() - properties.getyAxis();
logger.debug("POS {} x {}", xPos, yPos);
- logger.debug("SIZE {} x {}", properties.getWidth(), properties.getHeight());
+ logger.debug("SIZE {} x {}", properties.getWidth(),
+ properties.getHeight());
// translate according to page! rotation
int pageRotation = properties.getPageRotation();
AffineTransform translate = new AffineTransform();
- switch(pageRotation) {
- case 90:
- translate.setToTranslation(properties.getPageHeight()
- - (properties.getPageHeight()
- - properties.getyAxis()) - properties.getxAxis() + properties.getHeight(), properties.getxAxis() + properties.getHeight() - (properties.getPageHeight()
- - properties.getyAxis()));
+ switch (pageRotation) {
+ case 90:
+ translate.setToTranslation(
+ properties.getPageHeight()
+ - (properties.getPageHeight() - properties
+ .getyAxis()) - properties.getxAxis()
+ + properties.getHeight(),
+ properties.getxAxis()
+ + properties.getHeight()
+ - (properties.getPageHeight() - properties
+ .getyAxis()));
+ break;
+ case 180:
+ // translate.setToTranslation(properties.getPageWidth() -
+ // properties.getxAxis() - properties.getxAxis(),
+ // properties.getPageHeight() - properties.getyAxis() +
+ // properties.getHeight());
+ translate.setToTranslation(
+ properties.getPageWidth() - 2 * xPos,
+ properties.getPageHeight() - 2
+ * (yPos - properties.getHeight()));
+ break;
+ case 270:
+ translate.setToTranslation(-properties.getHeight() + yPos - xPos,
+ properties.getPageWidth() - (yPos - properties.getHeight())
+ - xPos);
break;
- case 180:
- //translate.setToTranslation(properties.getPageWidth() - properties.getxAxis() - properties.getxAxis(),
- // properties.getPageHeight() - properties.getyAxis() + properties.getHeight());
- translate.setToTranslation(properties.getPageWidth() - 2 * xPos,properties.getPageHeight() - 2 * (yPos - properties.getHeight()));
- break;
- case 270:
- translate.setToTranslation(-properties.getHeight() + yPos - xPos, properties.getPageWidth() - (yPos - properties.getHeight()) - xPos);
- break;
}
translate.transform(upDst, upDst);
translate.transform(llDst, llDst);
-
+
rect.setUpperRightX((float) upDst.getX());
rect.setUpperRightY((float) upDst.getY());
rect.setLowerLeftY((float) llDst.getY());
diff --git a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java
index 55a6d832..d7ef6fae 100644
--- a/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java
+++ b/pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java
@@ -36,6 +36,7 @@ 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.settings.SignatureProfileSettings;
import at.gv.egiz.pdfas.lib.impl.pdfbox.PDFBOXObject;
import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction;
@@ -50,10 +51,13 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
private PDFAsVisualSignatureDesigner designer;
private float rotationAngle = 0;
+
+ private SignatureProfileSettings signatureProfileSettings;
public PDFAsVisualSignatureProperties(ISettings settings, PDFBOXObject object,
- PdfBoxVisualObject visObj, PositioningInstruction pos) {
+ PdfBoxVisualObject visObj, PositioningInstruction pos, SignatureProfileSettings signatureProfileSettings) {
this.settings = settings;
+ this.signatureProfileSettings = signatureProfileSettings;
try {
main = visObj.getTable();
} catch (Throwable e) {
@@ -125,5 +129,10 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
public PDFAsVisualSignatureDesigner getDesigner() {
return designer;
}
+
+ public SignatureProfileSettings getSignatureProfileSettings() {
+ return signatureProfileSettings;
+ }
+
}