From 5746571fe4513b454349be428230300907d86b2b Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 1 Jul 2014 16:39:54 +0200 Subject: Added Preview Image generation of visual Signature block for PDF-Over --- .../gv/egiz/pdfas/lib/test/mains/PDFToImage.java | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 pdf-as-lib/src/test/java/at/gv/egiz/pdfas/lib/test/mains/PDFToImage.java (limited to 'pdf-as-lib/src/test') 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 signatureProfiles = new ArrayList(); + + List signaturePDFAProfiles = new ArrayList(); + + Iterator 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 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 { + + } + } + +} -- cgit v1.2.3