aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-05-08 11:57:22 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-05-08 11:57:22 +0200
commit5e65a0aa96300e24a6dc7d4be64cf6745f325fc5 (patch)
tree4933e428c0cfca799eb3d573fc1868cc184b7736 /pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl
parent6a588fa992b35eb3e31a3f183cbb7639288d2a57 (diff)
downloadpdf-as-4-5e65a0aa96300e24a6dc7d4be64cf6745f325fc5.tar.gz
pdf-as-4-5e65a0aa96300e24a6dc7d4be64cf6745f325fc5.tar.bz2
pdf-as-4-5e65a0aa96300e24a6dc7d4be64cf6745f325fc5.zip
Added Rotation for pdfbox signatures
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java144
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java5
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java141
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java4
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java8
5 files changed, 208 insertions, 94 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
index c74b15b0..68257861 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PADESPDFBOXSigner.java
@@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Iterator;
import java.util.List;
import org.apache.pdfbox.cos.COSDictionary;
@@ -41,13 +42,21 @@ import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageNode;
import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.pdmodel.graphics.color.PDGamma;
import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent;
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceCharacteristicsDictionary;
import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureOptions;
+import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
+import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import sun.tools.jar.SignatureFile;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.common.messages.MessageResolver;
import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
@@ -193,14 +202,15 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
IPDFVisualObject visualObject = stamper.createVisualPDFObject(
pdfObject, main);
- /*PDDocument originalDocument = PDDocument
- .load(new ByteArrayInputStream(pdfObject.getStatus()
- .getPdfObject().getOriginalDocument()));*/
+ /*
+ * PDDocument originalDocument = PDDocument .load(new
+ * ByteArrayInputStream(pdfObject.getStatus()
+ * .getPdfObject().getOriginalDocument()));
+ */
PositioningInstruction positioningInstruction = Positioning
- .determineTablePositioning(tablePos, "",
- doc, visualObject,
- legacy32Position);
+ .determineTablePositioning(tablePos, "", doc,
+ visualObject, legacy32Position);
SignaturePositionImpl position = new SignaturePositionImpl();
position.setX(positioningInstruction.getX());
@@ -218,10 +228,11 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
properties.buildSignature();
- /*ByteArrayOutputStream sigbos = new ByteArrayOutputStream();
- sigbos.write(StreamUtils.inputStreamToByteArray(properties
- .getVisibleSignature()));
- sigbos.close();*/
+ /*
+ * ByteArrayOutputStream sigbos = new ByteArrayOutputStream();
+ * sigbos.write(StreamUtils.inputStreamToByteArray(properties
+ * .getVisibleSignature())); sigbos.close();
+ */
if (signaturePlaceholderData != null) {
// Placeholder found!
@@ -238,14 +249,18 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
int pageNumber = positioningInstruction.getPage();
rootPages.getAllKids(kids);
PDPage page = kids.get(pageNumber);
-
- logger.info("Placeholder name: " + signaturePlaceholderData.getPlaceholderName());
- COSDictionary xobjectsDictionary = (COSDictionary) page.findResources().getCOSDictionary()
+
+ logger.info("Placeholder name: "
+ + signaturePlaceholderData.getPlaceholderName());
+ COSDictionary xobjectsDictionary = (COSDictionary) page
+ .findResources().getCOSDictionary()
.getDictionaryObject(COSName.XOBJECT);
- xobjectsDictionary.setItem(signaturePlaceholderData.getPlaceholderName(), img);
+ xobjectsDictionary.setItem(
+ signaturePlaceholderData.getPlaceholderName(), img);
xobjectsDictionary.setNeedToBeUpdate(true);
page.findResources().getCOSObject().setNeedToBeUpdate(true);
- logger.info("Placeholder name: " + signaturePlaceholderData.getPlaceholderName());
+ logger.info("Placeholder name: "
+ + signaturePlaceholderData.getPlaceholderName());
}
if (positioningInstruction.isMakeNewPage()) {
@@ -283,51 +298,98 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
e);
}
}
-
- /*if(signatureProfileSettings.isPDFA()) {
- // Check for PDF-UA
- PDDocumentCatalog root = doc.getDocumentCatalog();
- PDStructureTreeRoot treeRoot = root.getStructureTreeRoot();
- if(treeRoot != null) {
- // Handle as PDF-UA
- logger.info("Tree Root: {}", treeRoot.toString());
- PDStructureElement docElement = PDFBoxTaggingUtils.getDocumentElement(treeRoot);
- PDStructureElement sigBlock = new PDStructureElement("Table", docElement);
- root.getCOSObject().setNeedToBeUpdate(true);
- docElement.getCOSObject().setNeedToBeUpdate(true);
- treeRoot.getCOSObject().setNeedToBeUpdate(true);
- sigBlock.setTitle("Signature Table");
- }
- }*/
+
+ /*
+ * if(signatureProfileSettings.isPDFA()) { // Check for PDF-UA
+ * PDDocumentCatalog root = doc.getDocumentCatalog();
+ * PDStructureTreeRoot treeRoot = root.getStructureTreeRoot();
+ * if(treeRoot != null) { // Handle as PDF-UA
+ * logger.info("Tree Root: {}", treeRoot.toString());
+ * PDStructureElement docElement =
+ * PDFBoxTaggingUtils.getDocumentElement(treeRoot);
+ * PDStructureElement sigBlock = new PDStructureElement("Table",
+ * docElement); root.getCOSObject().setNeedToBeUpdate(true);
+ * docElement.getCOSObject().setNeedToBeUpdate(true);
+ * treeRoot.getCOSObject().setNeedToBeUpdate(true);
+ * sigBlock.setTitle("Signature Table"); } }
+ */
options.setPreferedSignatureSize(0x1000);
options.setPage(positioningInstruction.getPage());
- options.setVisualSignature(properties
- .getVisibleSignature());
+ options.setVisualSignature(properties.getVisibleSignature());
}
doc.addSignature(signature, signer, options);
+ if (requestedSignature.isVisual()) {
+
+ // if(requestedSignature.getSignaturePosition().)
+
+ PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
+ if (acroForm != null) {
+
+ @SuppressWarnings("unchecked")
+ List<PDField> fields = acroForm.getFields();
+ PDSignatureField signatureField = null;
+
+ if (fields != null) {
+ for (PDField pdField : fields) {
+ if (pdField instanceof PDSignatureField) {
+ if (((PDSignatureField) pdField).getSignature().getDictionary()
+ .equals(signature.getDictionary())) {
+ signatureField = (PDSignatureField) pdField;
+ }
+ }
+ }
+ } else {
+ logger.warn("Failed to apply rotation! [Cannot find Field list in acroForm!]");
+ }
+
+ if(signatureField != null) {
+ if (signatureField.getWidget() != null) {
+ if (signatureField.getWidget()
+ .getAppearanceCharacteristics() == null) {
+ PDAppearanceCharacteristicsDictionary dict = new PDAppearanceCharacteristicsDictionary(
+ new COSDictionary());
+ signatureField.getWidget()
+ .setAppearanceCharacteristics(dict);
+ }
+
+ if (signatureField.getWidget()
+ .getAppearanceCharacteristics() != null) {
+ signatureField.getWidget()
+ .getAppearanceCharacteristics()
+ .setRotation(90);
+ }
+ }
+ } else {
+ logger.warn("Failed to apply rotation! [Cannot find signature Field!]");
+ }
+ } else {
+ logger.warn("Failed to apply rotation! [Cannot find acroForm!]");
+ }
+ }
+
// pdfbox patched (FIS -> IS)
doc.saveIncremental(fis, fos);
fis.close();
fos.flush();
fos.close();
fos = null;
-
+
fis = new FileInputStream(new File(fisTmpFile));
// write to resulting output stream
- //ByteArrayOutputStream bos = new ByteArrayOutputStream();
- //bos.write();
- //bos.close();
-
+ // ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ // bos.write();
+ // bos.close();
- pdfObject.setSignedDocument(StreamUtils.inputStreamToByteArray(fis));
+ pdfObject
+ .setSignedDocument(StreamUtils.inputStreamToByteArray(fis));
fis.close();
fis = null;
System.gc();
-
+
helper.deleteFile(fisTmpFile);
} catch (IOException e) {
@@ -341,7 +403,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants {
throw new PdfAsException("error.pdf.sig.01", e);
} finally {
logger.info("Signature done!");
-
+
}
}
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java
index 528e4d6a..1c001b0c 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java
@@ -65,7 +65,7 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
//AffineTransform transform = pdfStructure.getAffineTransform();
// rectangle, formatter, image. /AcroForm/DR/XObject contains that form
- this.pdfBuilder.createSignatureRectangle(pdSignatureField, properties);
+ this.pdfBuilder.createSignatureRectangle(pdSignatureField, properties, properties.getRotation());
this.pdfBuilder.createFormaterRectangle(properties.getFormaterRectangleParams());
PDRectangle formater = pdfStructure.getFormaterRectangle();
@@ -79,7 +79,8 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator {
this.pdfBuilder.createHolderForm(holderFormResources, holderFormStream, formater);
// that is /AP entry the appearance dictionary.
- this.pdfBuilder.createAppearanceDictionary(pdfStructure.getHolderForm(), pdSignatureField);
+ this.pdfBuilder.createAppearanceDictionary(pdfStructure.getHolderForm(), pdSignatureField,
+ properties.getRotation());
// inner formstream, form and resource (hlder form containts inner form)
this.pdfBuilder.createInnerFormStream(template);
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 ea26c778..f7a6c824 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
@@ -2,6 +2,7 @@ package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox;
import java.awt.Color;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -71,10 +72,10 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
logger.info("Drawing Table:");
abstractTable.dumpTable();
- if(abstractTable.getBGColor() != null) {
+ if (abstractTable.getBGColor() != null) {
contentStream.setNonStrokingColor(abstractTable.getBGColor());
contentStream.fillRect(x, y, abstractTable.getWidth(),
- abstractTable.getHeight());
+ abstractTable.getHeight());
contentStream.setNonStrokingColor(Color.BLACK);
}
float total = 0;
@@ -125,7 +126,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
yheight = y + abstractTable.getHeight();
}
for (int i = 0; i <= cols; i++) {
- if(subtable && i == cols) {
+ if (subtable && i == cols) {
continue;
}
logger.info("COL LINE: {} {} {} {}", nextx, ypos, nextx,
@@ -156,21 +157,24 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
String text = (String) cell.getValue();
float ttexty = texty - padding - fontSize;
- //COSName name = COSName.getPDFName("ANDI_TAG!");
- //contentStream.beginMarkedContentSequence(COSName.ALT, name);
- String fontName = textFont.equals(PDType1Font.COURIER) ? "COURIER" : "HELVETICA";
-
+ // COSName name = COSName.getPDFName("ANDI_TAG!");
+ // contentStream.beginMarkedContentSequence(COSName.ALT,
+ // name);
+ String fontName = textFont.equals(PDType1Font.COURIER) ? "COURIER"
+ : "HELVETICA";
+
contentStream.beginText();
-
- if(innerFormResources.getFonts().containsValue(textFont)) {
+
+ if (innerFormResources.getFonts().containsValue(textFont)) {
String fontID = getFontID(textFont);
logger.info("Using Font: " + fontID);
- contentStream.appendRawCommands("/" + fontID + " " + fontSize + " Tf\n");
+ contentStream.appendRawCommands("/" + fontID + " "
+ + fontSize + " Tf\n");
} else {
contentStream.setFont(textFont, fontSize);
}
logger.info("Writing: " + textx + " : " + ttexty + " = "
- + text + " as " + cell.getType() + " w " + fontName);
+ + text + " as " + cell.getType() + " w " + fontName);
contentStream.moveTextPositionByAmount(textx, ttexty);
if (text.contains("\n")) {
@@ -256,16 +260,17 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
private Map<String, ImageObject> images = new HashMap<String, ImageObject>();
private String getFontID(PDFont font) {
- Iterator<java.util.Map.Entry<String, PDFont>> it = innerFormResources.getFonts().entrySet().iterator();
- while(it.hasNext()) {
+ Iterator<java.util.Map.Entry<String, PDFont>> it = innerFormResources
+ .getFonts().entrySet().iterator();
+ while (it.hasNext()) {
java.util.Map.Entry<String, PDFont> entry = it.next();
- if(entry.getValue().equals(font)) {
+ if (entry.getValue().equals(font)) {
return entry.getKey();
}
}
return "";
}
-
+
public PDFAsVisualSignatureBuilder(
PDFAsVisualSignatureProperties properties, ISettings settings) {
this.properties = properties;
@@ -292,7 +297,8 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
getStructure().setTemplate(template);
}
- private void readTableResources(PDFBoxTable table, PDDocument template) throws PdfAsException, IOException {
+ private void readTableResources(PDFBoxTable table, PDDocument template)
+ throws PdfAsException, IOException {
float[] colsSizes = table.getColsRelativeWith();
int max_cols = table.getColCount();
@@ -322,18 +328,16 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
logger.info("Col: " + cols_idx + " : " + colsSizes[cols_idx]);
}
- /*if(!addedFonts.contains(table.getFont().getFont(null))) {
- PDFont font = table.getFont().getFont(template);
- addedFonts.add(font);
- innerFormResources.addFont(font);
- }
-
- if(!addedFonts.contains(table.getValueFont().getFont(null))) {
- PDFont font = table.getValueFont().getFont(template);
- addedFonts.add(font);
- innerFormResources.addFont(font);
- }*/
-
+ /*
+ * if(!addedFonts.contains(table.getFont().getFont(null))) { PDFont font
+ * = table.getFont().getFont(template); addedFonts.add(font);
+ * innerFormResources.addFont(font); }
+ *
+ * if(!addedFonts.contains(table.getValueFont().getFont(null))) { PDFont
+ * font = table.getValueFont().getFont(template); addedFonts.add(font);
+ * innerFormResources.addFont(font); }
+ */
+
for (int i = 0; i < table.getRowCount(); i++) {
ArrayList<Entry> row = table.getRow(i);
for (int j = 0; j < row.size(); j++) {
@@ -372,19 +376,20 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
float size = (int) Math.floor((double) width);
size -= 2 * padding;
logger.debug("Scaling image to: " + size);
-
- if(table.style != null) {
- if(table.style.getImageScaleToFit() != null) {
- size = table.style.getImageScaleToFit().getWidth();
+
+ if (table.style != null) {
+ if (table.style.getImageScaleToFit() != null) {
+ size = table.style.getImageScaleToFit()
+ .getWidth();
}
}
-
+
PDXObjectImage pdImage = new PDJpeg(template, img);
ImageObject image = new ImageObject(pdImage, size);
images.put(img_ref, image);
innerFormResources.addXObject(pdImage, "Im");
}
- } else if(cell.getType() == Entry.TYPE_TABLE) {
+ } else if (cell.getType() == Entry.TYPE_TABLE) {
PDFBoxTable tbl_value = (PDFBoxTable) cell.getValue();
readTableResources(tbl_value, template);
}
@@ -402,10 +407,10 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
innerFormResources = new PDResources();
getStructure().getPage().setResources(innerFormResources);
readTableResources(properties.getMainTable(), template);
-
+
PDPageContentStream stream = new PDPageContentStream(template,
getStructure().getPage());
- //stream.setFont(PDType1Font.COURIER, 5);
+ // stream.setFont(PDType1Font.COURIER, 5);
drawTable(getStructure().getPage(), stream, 1, 1,
properties.getMainTable(), template, false);
@@ -450,7 +455,15 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
* String imgFormComment = "q " + 100 + " 0 0 50 0 0 cm /" + imageName +
* " Do Q\n";
*/
- String holderFormComment = "q 1 0 0 1 0 0 cm /" + innerFormName
+ double m00 = getStructure().getAffineTransform().getScaleX();
+ double m10 = getStructure().getAffineTransform().getShearY();
+ double m01 = getStructure().getAffineTransform().getShearX();
+ double m11 = getStructure().getAffineTransform().getScaleY();
+ double m02 = getStructure().getAffineTransform().getTranslateX();
+ double m12 = getStructure().getAffineTransform().getTranslateY();
+
+ String holderFormComment = "q " + m00 + " " + m10 + " " + m01 + " "
+ + m11 + " " + m02 + " " + m12 + " cm /" + innerFormName
+ " Do Q \n";
// String innerFormComment = "q 1 0 0 1 0 0 cm /" + imageObjectName +
// " Do Q\n";
@@ -522,14 +535,36 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
}
public void createSignatureRectangle(PDSignatureField signatureField,
- PDFAsVisualSignatureDesigner properties) throws IOException {
+ PDFAsVisualSignatureDesigner properties, float degrees)
+ throws IOException {
PDRectangle rect = new PDRectangle();
- rect.setUpperRightX(properties.getxAxis() + properties.getWidth() + 10);
- rect.setUpperRightY(properties.getPageHeight() - properties.getyAxis());
- rect.setLowerLeftY(properties.getPageHeight() - properties.getyAxis()
- - properties.getHeight() - 10);
- rect.setLowerLeftX(properties.getxAxis());
+
+ Point2D upSrc = new Point2D.Float();
+ upSrc.setLocation(properties.getxAxis() + properties.getWidth() + 10,
+ properties.getPageHeight() - properties.getyAxis());
+
+ Point2D llSrc = new Point2D.Float();
+ llSrc.setLocation(properties.getxAxis(), properties.getPageHeight()
+ - properties.getyAxis() - properties.getHeight() - 10);
+ 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);
+
+ rect.setUpperRightX((float) upDst.getX());
+ rect.setUpperRightY((float) upDst.getY());
+ rect.setLowerLeftY((float) llDst.getY());
+ rect.setLowerLeftX((float) llDst.getX());
+ logger.info("rectangle of signature has been created: {}",
+ rect.toString());
signatureField.getWidget().setRectangle(rect);
getStructure().setSignatureRectangle(rect);
logger.info("rectangle of signature has been created");
@@ -538,6 +573,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
public void createAffineTransform(byte[] params) {
AffineTransform transform = new AffineTransform(params[0], params[1],
params[2], params[3], params[4], params[5]);
+ // transform.rotate(90);
getStructure().setAffineTransform(transform);
logger.info("Matrix has been added");
}
@@ -555,10 +591,14 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
public void createFormaterRectangle(float[] params) {
PDRectangle formrect = new PDRectangle();
- formrect.setUpperRightX(params[0]);
- formrect.setUpperRightY(params[1]);
- formrect.setLowerLeftX(params[2]);
- formrect.setLowerLeftY(params[3]);
+ float[] translated = new float[4];
+ getStructure().getAffineTransform().transform(params, 0, translated, 0,
+ 2);
+
+ formrect.setUpperRightX(translated[0]);
+ formrect.setUpperRightY(translated[1]);
+ formrect.setLowerLeftX(translated[2]);
+ formrect.setLowerLeftY(translated[3]);
getStructure().setFormaterRectangle(formrect);
logger.info("Formater rectangle has been created");
@@ -591,14 +631,17 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder {
}
public void createAppearanceDictionary(PDXObjectForm holderForml,
- PDSignatureField signatureField) throws IOException {
+ PDSignatureField signatureField, float degrees) throws IOException {
PDAppearanceDictionary appearance = new PDAppearanceDictionary();
appearance.getCOSObject().setDirect(true);
PDAppearanceStream appearanceStream = new PDAppearanceStream(
holderForml.getCOSStream());
-
+ AffineTransform transform = new AffineTransform();
+ transform.setToIdentity();
+ transform.rotate(Math.toRadians(degrees));
+ appearanceStream.setMatrix(transform);
appearance.setNormalAppearance(appearanceStream);
signatureField.getWidget().setAppearance(appearance);
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java
index b2183753..4bc33cba 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureDesigner.java
@@ -398,4 +398,8 @@ public class PDFAsVisualSignatureDesigner {
"That method is not yet implemented");
}
+ public float getRotation() {
+ return this.properties.getRotation();
+ }
+
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java
index 6b1edf13..9ccf4eed 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java
@@ -1,6 +1,5 @@
package at.gv.egiz.pdfas.lib.impl.stamping.pdfbox;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
@@ -21,6 +20,8 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
private PDFBoxTable main;
private PDFAsVisualSignatureDesigner designer;
+
+ private float rotationAngle = 0;
public PDFAsVisualSignatureProperties(ISettings settings, PDFObject object,
PdfBoxVisualObject visObj, PositioningInstruction pos) {
@@ -31,6 +32,7 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
} catch (Throwable e) {
e.printStackTrace();
}
+ this.rotationAngle = pos.getRotation();
try {
PDDocument origDoc = object.getDocument();
@@ -58,6 +60,8 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties {
}
+ public float getRotation() {
+ return this.rotationAngle;
+ }
-
}