aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-pdfbox/src/main/java/at/gv
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-pdfbox/src/main/java/at/gv')
-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.java113
-rw-r--r--pdf-as-pdfbox/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java10
3 files changed, 76 insertions, 52 deletions
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 250d1242..8095911d 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
@@ -325,7 +325,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
properties = new PDFAsVisualSignatureProperties(
pdfObject.getStatus().getSettings(), pdfObject,
(PdfBoxVisualObject) visualObject,
- positioningInstruction);
+ positioningInstruction, signatureProfileSettings);
properties.buildSignature();
@@ -767,7 +767,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 e7672894..33e4102d 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
@@ -26,8 +26,6 @@ package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -37,11 +35,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.imageio.ImageIO;
-
-import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.io.IOUtils;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
@@ -70,7 +64,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 +121,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 +176,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 +211,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()) {
+ 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 +241,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 +270,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);
}
}
@@ -312,24 +315,24 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder implements
String holderFormComment = "q " + m00 + " " + m10 + " " + m01 + " "
+ m11 + " " + m02 + " " + m12 + " cm /" + innerFormName
- + " Do Q \n";
-
+ + " Do Q";
+
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());
appendRawCommands(getStructure().getHolderFormStream()
- .createOutputStream(), holderFormComment);
+ .createOutputStream(), holderFormComment.trim().replace("\n", "").replace("\r", ""));
appendRawCommands(getStructure().getInnterFormStream()
- .createOutputStream(), innerFormComment);
+ .createOutputStream(), innerFormComment.trim().replace("\n", "").replace("\r", ""));
// appendRawCommands(getStructure().getImageFormStream().createOutputStream(),
// imgFormComment);
logger.debug("Injected apereance stream to pdf");
@@ -398,55 +401,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 ea20858f..3fdc6b4c 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;
@@ -51,11 +52,14 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
private float rotationAngle = 0;
+ private SignatureProfileSettings signatureProfileSettings;
+
private String alternativeTableCaption="";
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) {
@@ -128,6 +132,10 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
return designer;
}
+ public SignatureProfileSettings getSignatureProfileSettings() {
+ return signatureProfileSettings;
+ }
+
public String getAlternativeTableCaption() {
return alternativeTableCaption;
}