aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/test/java/at/gv/egiz/pdfas
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-07-01 16:39:54 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-07-01 16:40:38 +0200
commit5746571fe4513b454349be428230300907d86b2b (patch)
tree7a232cfb49f268c4952f462a4741b740c488ff10 /pdf-as-lib/src/test/java/at/gv/egiz/pdfas
parent19b27e99968233a285965daba6cc1e19a7406ce6 (diff)
downloadpdf-as-4-5746571fe4513b454349be428230300907d86b2b.tar.gz
pdf-as-4-5746571fe4513b454349be428230300907d86b2b.tar.bz2
pdf-as-4-5746571fe4513b454349be428230300907d86b2b.zip
Added Preview Image generation of visual Signature block for PDF-Over
Diffstat (limited to 'pdf-as-lib/src/test/java/at/gv/egiz/pdfas')
-rw-r--r--pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/PDFToImage.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/PDFToImage.java b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/PDFToImage.java
new file mode 100644
index 00000000..0708e249
--- /dev/null
+++ b/pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/PDFToImage.java
@@ -0,0 +1,87 @@
+package at.gv.egiz.pdfas.lib.test.mains;
+
+import iaik.x509.X509Certificate;
+
+import java.awt.Image;
+import java.awt.image.RenderedImage;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.imageio.ImageIO;
+
+import sun.misc.IOUtils;
+import at.gv.egiz.pdfas.common.settings.ISettings;
+import at.gv.egiz.pdfas.lib.api.ByteArrayDataSink;
+import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource;
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.DataSource;
+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.lib.api.sign.SignResult;
+
+public class PDFToImage {
+
+ private static final String PDF_FILE = "/home/afitzek/simple.pdf";
+ private static final String IMG_FILE = "/home/afitzek/simple.png";
+
+ public static final String targetFolder = "/home/afitzek/tmp/sigres/";
+
+ public static void main(String[] args) {
+ String user_home = System.getProperty("user.home");
+ String pdfas_dir = user_home + File.separator + ".pdfas";
+ PdfAs pdfas = PdfAsFactory.createPdfAs(new File(pdfas_dir));
+ try {
+ Configuration config = pdfas.getConfiguration();
+ ISettings settings = (ISettings) config;
+ List<String> signatureProfiles = new ArrayList<String>();
+
+ List<String> signaturePDFAProfiles = new ArrayList<String>();
+
+ Iterator<String> itKeys = settings.getFirstLevelKeys(
+ "sig_obj.types.").iterator();
+ while (itKeys.hasNext()) {
+ String key = itKeys.next();
+ String profile = key.substring("sig_obj.types.".length());
+ System.out.println("[" + profile + "]: "
+ + settings.getValue(key));
+ if (settings.getValue(key).equals("on")) {
+ signatureProfiles.add(profile);
+ if (profile.contains("PDFA")) {
+ signaturePDFAProfiles.add(profile);
+ }
+ }
+ }
+
+ Iterator<String> itProfiles = signatureProfiles.iterator();
+ while (itProfiles.hasNext()) {
+ String profile = itProfiles.next();
+ System.out.println("Testing " + profile);
+
+ X509Certificate cert = new X509Certificate(new FileInputStream(
+ "/home/afitzek/qualified.cer"));
+
+ SignParameter parameter = PdfAsFactory.createSignParameter(
+ config, null);
+ parameter.setSignatureProfileId(profile);
+ Image img = pdfas.generateVisibleSignaturePreview(parameter,
+ cert, 128);
+ if (img != null) {
+ ImageIO.write((RenderedImage) img, "png", new File(
+ targetFolder + profile + ".png"));
+ }
+ }
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ } finally {
+
+ }
+ }
+
+}