List of usage examples for com.lowagie.text.pdf PdfStamper close
public void close() throws DocumentException, IOException
From source file:sos.util.security.SOSPDFSignatur.java
License:Apache License
/** * PDF Signatur erzeugen// w w w .jav a 2 s . c o m * * @param privateKey Private Key * @param chain Certificate Chain * @param originalPdfName Original PDF Datei zur Signierung * @param outputPdfName Output (signierte) PDF Datei * @throws Exception */ public static void createSignatur(PrivateKey privateKey, Certificate[] chain, String originalPdfName, String outputPdfName) throws Exception { PdfReader reader = new PdfReader(originalPdfName); FileOutputStream fout = new FileOutputStream(outputPdfName); //createSignature(PdfReader reader, OutputStream os, char pdfVersion) //pdfVersion - the new pdf version or '\0' to keep the same version as // the original document PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0'); PdfSignatureAppearance sap = stp.getSignatureAppearance(); //setCrypto(PrivateKey privKey, Certificate[] certChain, CRL[] crlList, PdfName filter) // CRL - certificate revocation lists (CRLs) that have different formats but important common uses. // For example, all CRLs share the functionality of listing revoked certificates, and can be queried on whether or not they list a given certificate. // PdfName // SELF_SIGNED - The self signed filter // VERISIGN_SIGNED - The VeriSign filter // WINCER_SIGNED - The Windows Certificate Security sap.setCrypto(privateKey, chain, null, PdfSignatureAppearance.SELF_SIGNED); //sap.setCrypto(privateKey, chain, null,PdfSignatureAppearance.WINCER_SIGNED); sap.setReason(SOSPDFSignatur.reason); sap.setContact(SOSPDFSignatur.contact); sap.setLocation(SOSPDFSignatur.location); //GregorianCalendar cal = new GregorianCalendar(); //sap.setSignDate(cal); // comment next line to have an invisible signature //setVisibleSignature(Rectangle pageRect, int page, String fieldName) //sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null); //sap.setVisibleSignature(new Rectangle(100,100,200, 200), 1, null); if (SOSPDFSignatur.visible) {// todo //sap.setVisibleSignature(new Rectangle(200, 200, 400, 400), 1, null); } stp.close(); }
From source file:ud.ing.modi.controlador.ptorecarga.GeneracionFactura.java
public void generacionFacturaPDF() { try {/*from ww w. j a v a2 s .c om*/ System.out.println("Generaa"); cargarDatosFactura(); if (this.factura != null) { PdfReader reader = new PdfReader( "C:\\Users\\Administrador\\Dropbox\\Tesis\\Monedero Digital\\Factura_PtoRecarga.pdf"); String nombreFact = "D:\\REPOSITORIO TESIS2\\REPO\\MONEDERO_DIGITAL_APP\\MONEDERO_DIGITAL_APP_WEB\\src\\main\\webapp\\docs\\FACTURA_" + traerUsu() + ".pdf"; PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(nombreFact)); AcroFields formulario = stamp.getAcroFields(); formulario.setField("NUM_FACTURA", Integer.toString(this.factura.getCodFactura())); int mes = this.factura.getFechaCorte().getMonth() + 1; int anio = this.factura.getFechaCorte().getYear() + 1900; String fechaC = this.factura.getFechaCorte().getDate() + "-" + mes + "-" + anio; formulario.setField("FECHA_CORTE", fechaC); mes = this.factura.getFechaVencimiento().getMonth() + 1; anio = this.factura.getFechaVencimiento().getYear() + 1900; String fechaL = this.factura.getFechaVencimiento().getDate() + "-" + mes + "-" + anio; formulario.setField("FECHA_LIMITE", fechaL); formulario.setField("VALOR_PAGO", "$ " + Double.toString(this.factura.getValorTotalPago())); formulario.setField("COD_CLIENTE", Integer.toString(this.factura.getPuntoRecarga().getIdCliente())); formulario.setField("NOMBRE_CLIENTE", this.factura.getPuntoRecarga().getRazonSocial()); formulario.setField("NUM_RECARGAS", Integer.toString(this.factura.getNumTotalRecargas())); formulario.setField("VALOR_RECARGAS", "$ " + Double.toString(this.factura.getValorTotalRecargas())); formulario.setField("VALOR_COMISION", "$ " + Double.toString(this.factura.getValorCalculoComision())); stamp.setFormFlattening(true); stamp.close(); } } catch (IOException ex) { Logger.getLogger(GeneracionFactura.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(GeneracionFactura.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:vn.vfossa.signature.PdfContent.java
License:Open Source License
@Override public void addSignature(X509Certificate certificate, PrivateKey key) throws Exception { // TODO Auto-generated method stub Certificate cer[] = { certificate }; for (int index = path.length() - 1; index >= 0; index--) if (path.charAt(index) == '.') { signedPath = path.substring(0, index) + "_signed" + path.substring(index); break; }//from ww w. j a va 2 s . co m File file = new File(signedPath); FileOutputStream out = new FileOutputStream(file); int numOfPages = content.getNumberOfPages(); int numOfSignatures = content.getAcroFields().getSignatureNames().size() + 1; PdfStamper stp = PdfStamper.createSignature(content, out, '\0', null, true); PdfSignatureAppearance sap = stp.getSignatureAppearance(); int m = (numOfPages - 1) * 5 + (numOfSignatures - 1) * 200; try { Calendar ca = Calendar.getInstance(); ca.setTime(new Date()); sap.setSignDate(ca); } catch (Exception ex) { ex.printStackTrace(); } sap.setCrypto(key, cer, null, PdfSignatureAppearance.WINCER_SIGNED); sap.setVisibleSignature(new com.lowagie.text.Rectangle(m, 0, m + 200, 30), 1, null); stp.close(); //Files.delete(Paths.get(path)); content = new PdfReader(signedPath); }