summaryrefslogtreecommitdiff
path: root/pdf-over-signer
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-08-04 16:08:42 +0200
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-08-04 16:08:42 +0200
commit256a1b2cfbc72c33eb08d361591bdb3f52a34b64 (patch)
tree3487d163449d73501cfdf4224ae1404a4916a6b4 /pdf-over-signer
parente1b8dfe23f6d906f5f5df47cdefcf4fb0f765d55 (diff)
downloadpdf-over-256a1b2cfbc72c33eb08d361591bdb3f52a34b64.tar.gz
pdf-over-256a1b2cfbc72c33eb08d361591bdb3f52a34b64.tar.bz2
pdf-over-256a1b2cfbc72c33eb08d361591bdb3f52a34b64.zip
adjust pdf-as profile settings to fit custom logos
cf. #113
Diffstat (limited to 'pdf-over-signer')
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java15
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java17
2 files changed, 32 insertions, 0 deletions
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java
index c6613657..cea41bdd 100644
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java
+++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java
@@ -98,6 +98,21 @@ public class PdfAs4SignatureParameter {
if (sigNote != null) {
conf.setValue("sig_obj." + sigProfile + ".value.SIG_NOTE", sigNote);
}
+ if (this.signatureProfile == Profile.BASE_LOGO)
+ {
+ int emblemWidth = (this.emblem != null) ? this.emblem.getWidth() : 65;
+ int emblemHeight = (this.emblem != null) ? this.emblem.getHeight() : 65;
+ double aspectRatio = ((double)emblemWidth) / emblemHeight;
+ double targetWidth = 65.0;
+ double targetHeight = 65.0;
+ if (aspectRatio < 1)
+ targetWidth = 65.0 * aspectRatio;
+ else
+ targetHeight = 65.0 / aspectRatio;
+ conf.setValue("sig_obj." + sigProfile + ".table.main.Style.padding", "0");
+ conf.setValue("sig_obj." + sigProfile + ".pos", "w:"+targetWidth+";f:0");
+ conf.setValue("sig_obj." + sigProfile + ".table.main.Style.imagescaletofit", targetWidth+";"+targetHeight);
+ }
SignParameter param = PdfAsFactory.createSignParameter(conf, null, null);
param.setSignatureProfileId(sigProfile);
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
index e4d07b5d..952f1971 100644
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
+++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
@@ -62,6 +62,23 @@ public class PdfAs4Signer {
config.setValue("sig_obj." + sigProfile + ".value.SIG_NOTE", sigNote);
}
+ // TODO encapsulate this parameter magic in PdfAs4SignatureParameter
+ if (parameter.signatureProfile == Profile.BASE_LOGO)
+ {
+ int emblemWidth = (parameter.emblem != null) ? parameter.emblem.getWidth() : 65;
+ int emblemHeight = (parameter.emblem != null) ? parameter.emblem.getHeight() : 65;
+ double aspectRatio = ((double)emblemWidth) / emblemHeight;
+ double targetWidth = 65.0;
+ double targetHeight = 65.0;
+ if (aspectRatio < 1)
+ targetWidth = 65.0 * aspectRatio;
+ else
+ targetHeight = 65.0 / aspectRatio;
+ config.setValue("sig_obj." + sigProfile + ".table.main.Style.padding", "0");
+ config.setValue("sig_obj." + sigProfile + ".pos", "w:"+targetWidth+";f:0");
+ config.setValue("sig_obj." + sigProfile + ".table.main.Style.imagescaletofit", targetWidth+";"+targetHeight);
+ }
+
PdfAs4SigningState state = new PdfAs4SigningState();
ByteArrayOutputStream output = new ByteArrayOutputStream();
DataSource input = new ByteArrayDataSource(parameter.inputDocument.getByteArray());