List of usage examples for com.lowagie.text.pdf PdfStamper getAcroFields
public AcroFields getAcroFields()
AcroFields
object that allows to get and set field values and to merge FDF forms. From source file:questions.stamppages.StampAndAddColumns.java
public static void main(String[] args) { try {/*from w w w. j ava 2 s. co m*/ PdfReader reader = new PdfReader(RESOURCE); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); AcroFields form = stamper.getAcroFields(); form.setField("Who", "world"); ColumnText ct = new ColumnText(stamper.getOverContent(1)); String line; Phrase p; BufferedReader br = new BufferedReader(new FileReader(TXT)); while ((line = br.readLine()) != null) { p = new Phrase(line + "\n"); ct.addText(p); } int status = ColumnText.START_COLUMN; ct.setSimpleColumn(100, 700, 495, 100); status = ct.go(); int pageCt = 1; while (ColumnText.hasMoreText(status)) { stamper.insertPage(++pageCt, reader.getPageSize(1)); ct.setYLine(700); ct.setCanvas(stamper.getOverContent(pageCt)); status = ct.go(); } stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:ud.ing.modi.controlador.ptorecarga.GeneracionFactura.java
public void generacionFacturaPDF() { try {/*from w ww . j a va2 s . c o m*/ 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); } }