aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-cli
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-cli')
-rw-r--r--pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/RotatedPDFTest.java116
-rw-r--r--pdf-as-cli/src/test/resources/rotate_090.pdfbin0 -> 87083 bytes
-rw-r--r--pdf-as-cli/src/test/resources/rotate_180.pdfbin0 -> 87080 bytes
-rw-r--r--pdf-as-cli/src/test/resources/rotate_270.pdfbin0 -> 87077 bytes
-rw-r--r--pdf-as-cli/src/test/resources/simple_rotated_0.pdfbin0 -> 6257 bytes
-rw-r--r--pdf-as-cli/src/test/resources/simple_rotated_180.pdfbin0 -> 6145 bytes
-rw-r--r--pdf-as-cli/src/test/resources/simple_rotated_270.pdfbin0 -> 6145 bytes
-rw-r--r--pdf-as-cli/src/test/resources/simple_rotated_90.pdfbin0 -> 6144 bytes
-rw-r--r--pdf-as-cli/src/test/resources/test.p12bin0 -> 3372 bytes
9 files changed, 116 insertions, 0 deletions
diff --git a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/RotatedPDFTest.java b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/RotatedPDFTest.java
new file mode 100644
index 00000000..fcf766b1
--- /dev/null
+++ b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/RotatedPDFTest.java
@@ -0,0 +1,116 @@
+package at.gv.egiz.pdfas.cli.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.KeyStore;
+
+import javax.activation.DataSource;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.IOUtils;
+
+import at.gv.egiz.pdfas.common.exceptions.PDFASError;
+import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource;
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.PdfAs;
+import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
+import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner;
+import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore;
+
+public class RotatedPDFTest {
+
+ private static final String[] PDF_SOURCE_FILES = new String[] {
+ "/simple_rotated_0.pdf",
+ "/rotate_090.pdf",
+ "/rotate_180.pdf",
+ "/rotate_270.pdf"
+ /*,
+ "/simple_rotated_90.pdf",
+ "/simple_rotated_180.pdf",
+ "/simple_rotated_270.pdf"*/
+ };
+
+ private static final String[] PDF_TARGET_PREFIX_FILES = new String[] {
+ "rot0",
+ "rot90",
+ "rot180",
+ "rot270"
+ };
+
+ private static final String[] POS_STRINGS = new String[] {
+ null,
+ "x:0;y:50",
+ "x:0;y:50;p:new",
+ "x:100;y:300",
+ "x:100;y:300;r:90",
+ "x:100;y:300;r:180",
+ "x:100;y:300;r:270",
+ "x:400;y:500",
+ "x:500;y:400"
+ };
+
+ private static final String CFG_DIR = "../pdf-as-lib/src/configuration/";
+
+ private static final String TARGET_DIR = "/home/afitzek/tmp/rotate_test/";
+
+ private static final String KS_NAME = "/test.p12";
+ private static final String KS_TYPE = "PKCS12";
+ private static final String KS_PASS = "123456";
+ private static final String KS_KPASS = "123456";
+ private static final String KS_ALIAS = "ecc_test";
+
+ private static void signDokument(PdfAs pdfAs, IPlainSigner signer,
+ String posString, InputStream inputDokument, OutputStream stream) throws IOException, PDFASError {
+ Configuration configuration = pdfAs.getConfiguration();
+
+ DataSource source = new ByteArrayDataSource(
+ IOUtils.toByteArray(inputDokument));
+
+ SignParameter signParameter = PdfAsFactory.createSignParameter(
+ configuration, source, stream);
+
+ signParameter.setPlainSigner(signer);
+ signParameter.setSignaturePosition(posString);
+ signParameter.setSignatureProfileId("SIGNATURBLOCK_SMALL_DE");
+
+ pdfAs.sign(signParameter);
+ }
+
+ public static void main(String[] args) {
+ try {
+ PdfAs pdfAs = PdfAsFactory.createPdfAs(new File(CFG_DIR));
+
+ KeyStore store = KeyStore.getInstance(KS_TYPE);
+ store.load(RotatedPDFTest.class.getResourceAsStream(KS_NAME),
+ KS_PASS.toCharArray());
+
+ IPlainSigner ksSigner = new PAdESSignerKeystore(store, KS_ALIAS,
+ KS_KPASS);
+
+ if(PDF_SOURCE_FILES.length != PDF_TARGET_PREFIX_FILES.length) {
+ throw new Exception("INPUT ARRAY SIZE MISSMATCH!");
+ }
+
+ for(int fileIdx = 0; fileIdx < PDF_SOURCE_FILES.length; fileIdx++) {
+ for(int posIdx = 0; posIdx < POS_STRINGS.length; posIdx++) {
+ String inputFile = PDF_SOURCE_FILES[fileIdx];
+ String outputFile = TARGET_DIR + PDF_TARGET_PREFIX_FILES[fileIdx]+"_" + POS_STRINGS[posIdx] + ".pdf";
+ String posString = POS_STRINGS[posIdx];
+ System.out.println("From " + inputFile + " => " + outputFile + "(" + posString + ")");
+ FileOutputStream fos = new FileOutputStream(outputFile);
+ signDokument(pdfAs, ksSigner, posString, RotatedPDFTest.class.getResourceAsStream(inputFile), fos);
+ fos.close();
+ }
+ }
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/pdf-as-cli/src/test/resources/rotate_090.pdf b/pdf-as-cli/src/test/resources/rotate_090.pdf
new file mode 100644
index 00000000..b9858ce3
--- /dev/null
+++ b/pdf-as-cli/src/test/resources/rotate_090.pdf
Binary files differ
diff --git a/pdf-as-cli/src/test/resources/rotate_180.pdf b/pdf-as-cli/src/test/resources/rotate_180.pdf
new file mode 100644
index 00000000..7aa7f790
--- /dev/null
+++ b/pdf-as-cli/src/test/resources/rotate_180.pdf
Binary files differ
diff --git a/pdf-as-cli/src/test/resources/rotate_270.pdf b/pdf-as-cli/src/test/resources/rotate_270.pdf
new file mode 100644
index 00000000..f715cd7b
--- /dev/null
+++ b/pdf-as-cli/src/test/resources/rotate_270.pdf
Binary files differ
diff --git a/pdf-as-cli/src/test/resources/simple_rotated_0.pdf b/pdf-as-cli/src/test/resources/simple_rotated_0.pdf
new file mode 100644
index 00000000..867f68db
--- /dev/null
+++ b/pdf-as-cli/src/test/resources/simple_rotated_0.pdf
Binary files differ
diff --git a/pdf-as-cli/src/test/resources/simple_rotated_180.pdf b/pdf-as-cli/src/test/resources/simple_rotated_180.pdf
new file mode 100644
index 00000000..ab8a0573
--- /dev/null
+++ b/pdf-as-cli/src/test/resources/simple_rotated_180.pdf
Binary files differ
diff --git a/pdf-as-cli/src/test/resources/simple_rotated_270.pdf b/pdf-as-cli/src/test/resources/simple_rotated_270.pdf
new file mode 100644
index 00000000..371c7168
--- /dev/null
+++ b/pdf-as-cli/src/test/resources/simple_rotated_270.pdf
Binary files differ
diff --git a/pdf-as-cli/src/test/resources/simple_rotated_90.pdf b/pdf-as-cli/src/test/resources/simple_rotated_90.pdf
new file mode 100644
index 00000000..c28486a8
--- /dev/null
+++ b/pdf-as-cli/src/test/resources/simple_rotated_90.pdf
Binary files differ
diff --git a/pdf-as-cli/src/test/resources/test.p12 b/pdf-as-cli/src/test/resources/test.p12
new file mode 100644
index 00000000..ec55d100
--- /dev/null
+++ b/pdf-as-cli/src/test/resources/test.p12
Binary files differ