List of usage examples for com.itextpdf.text.pdf PdfPTable setTotalWidth
public void setTotalWidth(final float columnWidth[]) throws DocumentException
From source file:se.inera.intyg.rehabstod.service.export.pdf.PageNumberingEventHandler.java
License:Open Source License
/** * Adds a header to every page.// www.j a va 2 s . c o m * * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(com.itextpdf.text.pdf.PdfWriter, * com.itextpdf.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { try { PdfPTable table = new PdfPTable(2); table.setTotalWidth(document.getPageSize().getWidth()); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.addCell(new Phrase(String.valueOf(writer.getPageNumber()), PdfExportConstants.TABLE_CELL_NORMAL)); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.writeSelectedRows(0, -1, document.left(), document.bottom(), writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } }
From source file:Servicios.SmLogistics.java
private void b_pago_formatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_pago_formatoActionPerformed // TODO add your handling code here: Session session = HibernateUtil.getSessionFactory().openSession(); try {/* w ww . j a va 2s . co m*/ Orden ord = (Orden) session.get(Orden.class, orden_act.getIdOrden()); Configuracion con = (Configuracion) session.get(Configuracion.class, 1); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); String formato = "PagoAXA.pdf";//ord.getCompania().getFormatoPago(); File folder = new File("reportes/" + ord.getIdOrden()); folder.mkdirs(); PdfReader reader = new PdfReader("imagenes/" + formato); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-Pago.pdf")); PdfContentByte cb = stamp.getUnderContent(1); AcroFields fdfDoc = stamp.getAcroFields(); cb.beginText(); //IMAGEN try { Image img = Image.getInstance("imagenes/" + con.getLogo()); img.setAbsolutePosition(25, 710); img.scaleAbsoluteWidth(75); img.scaleAbsoluteHeight(50); cb.addImage(img, true); } catch (Exception e) { e.printStackTrace(); } try { Image img_1 = Image.getInstance(ord.getCompania().getFoto()); img_1.setAbsolutePosition(500, 735); img_1.scaleAbsoluteWidth(80); img_1.scaleAbsoluteHeight(50); cb.addImage(img_1, true); } catch (Exception e) { e.printStackTrace(); } Foto foto = (Foto) session.createCriteria(Foto.class) .add(Restrictions.eq("orden.idOrden", orden_act.getIdOrden())).addOrder(Order.desc("fecha")) .setMaxResults(1).uniqueResult(); if (foto != null) { try { Image img_2 = Image .getInstance("ordenes/" + ord.getIdOrden() + "/miniatura/" + foto.getDescripcion()); img_2.setAbsolutePosition(480, 558); img_2.scaleAbsoluteWidth(90); img_2.scaleAbsoluteHeight(50); cb.addImage(img_2, true); } catch (Exception e) { } } //NOMBRE DEL TALLER if (con.getEmpresa() != null) fdfDoc.setField("NombreEmpresa", con.getEmpresa()); //DIRECCION DEL TALLER String direccion = ""; if (con.getDireccion() != null) direccion += con.getDireccion() + " "; if (con.getNo() != null) direccion += con.getNo() + " "; if (con.getColonia() != null) direccion += con.getColonia(); direccion = direccion.toUpperCase(); fdfDoc.setField("DireccionEmpresa", direccion); //Municipio, Estado, CP String municipio = ""; if (con.getMunicipio() != null) municipio += con.getMunicipio() + " "; if (con.getEstado() != null) municipio += con.getEstado() + " "; if (con.getCp() != null) municipio += con.getCp(); municipio = municipio.toUpperCase(); fdfDoc.setField("ColoniaEmpresa", municipio); //Pagina Web y Telefonos fdfDoc.setField("SitioEmpresa", "tracto.ddns.net"); fdfDoc.setField("TelefonoEmpresa", "(722) 199 24 04 / 275 19 45"); //Datos de la compaia fdfDoc.setField("Aseguradora1", ord.getCompania().getSocial()); if (ord.getCompania().getDireccion() != null) fdfDoc.setField("Aseguradora2", ord.getCompania().getDireccion()); if (ord.getCompania().getColonia() != null) fdfDoc.setField("Aseguradora3", ord.getCompania().getColonia()); /*if(ord.getCompania().getComentarios()!=null) fdfDoc.setField("Extra", ord.getCompania().getComentarios());*/ //Orden de trabajo fdfDoc.setField("Orden", "" + ord.getIdOrden()); //FECHA INGRESO if (ord.getFecha() != null) fdfDoc.setField("FechaRecepcion", ord.getFecha().toString()); //Marca fdfDoc.setField("Marca", ord.getMarca().getMarcaNombre()); //Tipo fdfDoc.setField("Modelo", "" + ord.getTipo().getTipoNombre()); //Placas if (ord.getNoPlacas() != null) fdfDoc.setField("Placas", "" + ord.getNoPlacas()); //Poliza if (ord.getPoliza() != null) fdfDoc.setField("Poliza", "" + ord.getPoliza()); //Siniestro if (ord.getSiniestro() != null) fdfDoc.setField("Siniestro", "" + ord.getSiniestro()); //Datos cliente if (ord.getClientes() != null) { fdfDoc.setField("Nombre", ord.getClientes().getNombre()); if (ord.getClientes().getContacto() != null) fdfDoc.setField("Contacto", ord.getClientes().getContacto()); } //Datos de atencion a clientes fdfDoc.setField("Tel1", "722 299 240 25"); fdfDoc.setField("Id1", "52*167862*13"); fdfDoc.setField("Email1", "atencionaclientes@tractoservicio.com"); fdfDoc.setField("Wat1", "722 299 240 25"); float tam[] = new float[] { 160, 80, 130, 170 }; Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD); PDF reporte = new PDF(); PdfPTable tabla = reporte.crearTabla(4, tam, 100, Element.ALIGN_LEFT); tabla.setTotalWidth(tam); BaseColor cabecera = BaseColor.GRAY; BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; if (formato.compareToIgnoreCase("PagoAXA.pdf") != 0) { tabla.addCell(reporte.celda("BANCO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("NO CONVENIO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("N DE CUENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell( reporte.celda("NOMBRE DE LA COMPAIA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); Cuenta[] cuentas = (Cuenta[]) ord.getCompania().getCuentas().toArray(new Cuenta[0]); if (cuentas.length > 0) { for (int i = 0; i < cuentas.length; i++) { tabla.addCell(reporte.celda(cuentas[i].getBanco(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(cuentas[i].getConvenio().toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(cuentas[i].getTransferencia(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(cuentas[i].getNombre(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } } tabla.completeRow(); tabla.writeSelectedRows(0, -1, 40, 420, cb); } DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); cb.setTextMatrix(160, 466); BaseFont bf = BaseFont.createFont(); cb.setFontAndSize(bf, 9); cb.showText("" + formatoPorcentaje.format(orden_act.getDeducible())); cb.setTextMatrix(450, 466); cb.showText("" + formatoPorcentaje.format(orden_act.getDemerito())); cb.endText(); stamp.close(); reporte.cerrar(); reporte.visualizar2("reportes/" + ord.getIdOrden() + "/" + valor + "-Pago.pdf"); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } if (session != null) if (session.isOpen()) session.close(); }
From source file:superlaskuttaja.logiikka.PdfExtractor.java
private void muodostaDokumentti(Document document, String laskunNumero, PdfWriter writer) throws DocumentException, SQLException, ParseException { document.open();/*from ww w. ja v a 2s. c o m*/ //---------------------------------------------------------------------- PdfPTable table1 = new PdfPTable(7); Font f1 = new Font(Font.FontFamily.HELVETICA, 10); Font f2 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font f3 = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); Font f4 = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); ResultSet rs = lataaja.getDbc() .executeQuery("select distinct Laskuttaja.yrityksenNimi, Laskuttaja.katuosoite,\n" + "Laskuttaja.postinumero, Laskuttaja.kaupunki, Lasku.paivays, Laskuttaja.alvTunniste,\n" + "Pankkiviivakoodi.erapaiva, Lasku.viivastyskorko, Pankkiviivakoodi.viiteTarkisteella,\n" + "T.nimi, Lasku.maksuehto, T.katuosoite, Laskuttaja.tilinumeronPankki,\n" + "T.postinumero, T.kaupunki, Laskuttaja.tilinumero, T.email, Laskuttaja.tilinumeronSwiftBic,\n" + "V.nimi, V.katuosoite, V.postinumero, V.kaupunki, V.email, Lasku.lisatiedot,\n" + "T.asiakasnumero, V.asiakasnumero, Laskuttaja.nimi, Laskuttaja.puhelinnumero,\n" + "Laskuttaja.sahkopostiOsoite, Pankkiviivakoodi.pankkiviivakoodi\n" + "from Lasku, Pankkiviivakoodi, Laskuttaja, Suorite, Asiakas T, Asiakas V\n" + "where Lasku.laskunNumero = " + laskunNumero + "\n" + "and Lasku.laskuttaja = Laskuttaja.yrityksenNimi\n" + "and Lasku.laskuttajanVersio = Laskuttaja.versio\n" + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n" + "and Lasku.laskunnumero = Suorite.lasku\n" + "and Suorite.tilaaja = T.asiakasnumero\n" + "and Suorite.tilaajanVersio = T.versio\n" + "and Suorite.vastaanottaja = V.asiakasnumero\n" + "and Suorite.vastaanottajanVersio = V.versio\n" + ""); rs.first(); table1.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table1.setLockedWidth(true); table1.setWidths(new int[] { 370, 100, 73, 100, 73, 100, 179 }); PdfPCell cell; Paragraph p; cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(1), f4); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("LASKU", f4); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(2), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(3) + " " + rs.getString(4), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pivys", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(pvmFormaatti1.format(pvmFormaatti3.parse(rs.getTimestamp(5).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Laskun numero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(laskunNumero, f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Alv-tunniste: " + rs.getString(6), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Erpiv", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(pvmFormaatti1.format(pvmFormaatti4.parse(rs.getDate(7).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viivstyskorko", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(Integer.toString(rs.getInt(8)) + ".0%", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); //Jos vastaanottaja on sama kuin tilaaja ei laiteta erikseen vastaanottajan tietoja nkyville. if (rs.getInt(25) == rs.getInt(26)) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(10), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viitenumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(9), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(12), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Maksuehto", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(11), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(14) + " " + rs.getString(15), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pankki", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(13), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(17), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Tilinumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(16), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Swift/BIC", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(18), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Listiedot", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(24), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); document.add(table1); } else { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Palvelun tilaaja", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viitenumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(9), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(10), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Maksuehto", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(11), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(12), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pankki", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(13), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(14) + " " + rs.getString(15), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Tilinumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(16), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(17), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Swift/BIC", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(18), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Palvelun vastaanottaja", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(19), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(20), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(21) + " " + rs.getString(22), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(23), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Listiedot", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(24), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); document.add(table1); } // Otetaan alemmas tulevia tietoja talteen. String[] alasTulevatTiedot = new String[] { rs.getString(9), rs.getString(1), rs.getString(27), rs.getString(13), rs.getString(2), rs.getString(28), rs.getString(16), rs.getString(3) + " " + rs.getString(4), rs.getString(29), rs.getString(18), rs.getString(30), }; //Muodostetaan suoritteiden taulukko. PdfPTable table2 = new PdfPTable(7); table2.setWidths(new int[] { 370, 100, 73, 100, 73, 100, 179 }); table2.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table2.setLockedWidth(true); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Kuvaus", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Mr", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Yks.", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(" hinta", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Alv %", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Alv ", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); rs = lataaja.getDbc().executeQuery( "select distinct kuvaus, maara, maaranYksikot, aHintaVeroton, alvProsentti, ((alvProsentti / 100.0) * aHintaVeroton * maara) as alvEuroa,\n" + "((1.0 + alvProsentti / 100.0) * aHintaVeroton * maara) as yht, alkuaika\n" + "from Suorite\n" + "where lasku = " + laskunNumero + "\n" + ""); while (rs.next()) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(1) + " " + pvmFormaatti1.format(pvmFormaatti3.parse(rs.getTimestamp(8).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(2, 2).toString(), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(3), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(4, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(5) + "%", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(6, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(7, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); } cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); rs = lataaja.getDbc().executeQuery( "select distinct sum(aHintaVeroton * maara), sum((alvProsentti / 100.0) * aHintaVeroton * maara)\n" + "from Suorite\n" + "where lasku = " + laskunNumero + "\n" + ""); rs.first(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Veroton hinta yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(1, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Arvonlisvero yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(2, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(4); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Yhteens", f3); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); rs = lataaja.getDbc() .executeQuery("select laskunSumma\n" + "from Lasku, Pankkiviivakoodi\n" + "where laskunNumero = " + laskunNumero + "\n" + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n" + ""); rs.first(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(1, 2).toString() + "", f3); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); document.add(table2); PdfPTable table3 = new PdfPTable(3); table3.setWidths(new int[] { 1, 1, 1 }); table3.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table3.setLockedWidth(true); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Pyydmme kyttmn maksaessanne viitenumeroa: " + alasTulevatTiedot[0], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(BOTTOM); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[1], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[2], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[3], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[4], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[5], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[6], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[7], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[8], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[9], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Virtuaaliviivakoodi: " + alasTulevatTiedot[10], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); table3.writeSelectedRows(0, -1, document.left(document.leftMargin()), table3.getTotalHeight() + document.bottom(document.bottomMargin()), writer.getDirectContent()); //---------------------------------------------------------------------- document.close(); }
From source file:tn.com.hitechart.eds.Util.pdfRpport.FirstPdf.java
private void createTable(Section subCatPart) throws BadElementException { //-------------------------- TAB POINTAGE -------------------// PdfPTable table = new PdfPTable(8); table.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); table.setLockedWidth(true);//from www. j a va 2s.co m // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); //----------- C1 --------------// PdfPCell c1 = new PdfPCell(new Phrase("Date Rapport")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C2 --------------// c1 = new PdfPCell(new Phrase("Technicien")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C3 --------------// c1 = new PdfPCell(new Phrase("Poinatge")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); //----------- C4 --------------// c1 = new PdfPCell(new Phrase("Matin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); //----------- C5 --------------// c1 = new PdfPCell(new Phrase("Aprs-Midi")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); //----------- C6 --------------// c1 = new PdfPCell(new Phrase("Rapport Journalier", catFont)); c1.setBorder(Rectangle.NO_BORDER); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(3); table.addCell(c1); //----------- C7 --------------// //----------- C8 --------------// table.setHeaderRows(1); //----------- R2 --------------// //----------- C1 --------------// c1 = new PdfPCell(new Phrase(tabDatapointage[0], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setRowspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase(user.getLogin(), dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setRowspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("Arrive")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(tabDatapointage[1], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(tabDatapointage[2], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C7 --------------// c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C8 --------------// c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- R3 --------------// c1 = new PdfPCell(new Phrase("Sortie")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(tabDatapointage[3], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(tabDatapointage[4], dataFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C7 --------------// c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); //----------- C8 --------------// c1 = new PdfPCell(new Phrase("")); c1.setBorder(Rectangle.NO_BORDER); table.addCell(c1); table.setSpacingAfter(10); subCatPart.add(table); //-------------------------- END TAB POINTAGE -------------------// // TODO: 20/01/2017 //--------------------------------- TASK ---------------------// PdfPTable tableTask = new PdfPTable(5); tableTask.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableTask.setLockedWidth(true); PdfPCell c2 = new PdfPCell(new Phrase("Dossiers Traits", catFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setColspan(5); c2.setBorder(Rectangle.NO_BORDER); tableTask.addCell(c2); tableTask.setHeaderRows(1); c2 = new PdfPCell(new Phrase("NDoss.", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); c2 = new PdfPCell(new Phrase("Client", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); c2 = new PdfPCell(new Phrase("Dure", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); c2 = new PdfPCell(new Phrase("Mission", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); c2 = new PdfPCell(new Phrase("Resultat", dataFont)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); tableTask.addCell(c2); if (tasks.isEmpty()) { c2 = new PdfPCell(new Phrase("Aucune Tache a t trait", catFontempty)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setColspan(5); tableTask.addCell(c2); } else { if (!dossiers.isEmpty()) { for (Dossier d : dossiers) { tableTask.addCell(d.getNumDoss()); tableTask.addCell(d.getClient()); tableTask.addCell(convertLongtoDurationfr(d.getTimeDuration())); tableTask.addCell(td.getTaskById(d.get_idTask()).getType()); tableTask.addCell(td.getTaskById(d.get_idTask()).getRes()); } } } tableTask.setSpacingAfter(10); subCatPart.add(tableTask); //-------------------------- END TAB TASK -------------------// // TODO: 20/01/2017 tab achat //-------------------------- TAB ACHAT -------------------// PdfPTable tableAchat = new PdfPTable(3); tableAchat.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableAchat.setLockedWidth(true); PdfPCell c3 = new PdfPCell(new Phrase("Frais Engags", catFont)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); c3.setColspan(3); c3.setBorder(Rectangle.NO_BORDER); tableAchat.addCell(c3); tableAchat.setHeaderRows(1); c3 = new PdfPCell(new Phrase("N.Doss.", dataFont)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); tableAchat.addCell(c3); c3 = new PdfPCell(new Phrase("Dsignation", dataFont)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); tableAchat.addCell(c3); c3 = new PdfPCell(new Phrase("Montant TCC", dataFont)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); tableAchat.addCell(c3); if (achats.isEmpty()) { c3 = new PdfPCell(new Phrase("la liste des achats est vide", catFontempty)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); c3.setColspan(3); tableAchat.addCell(c3); } else { for (Achat achat : achats) { tableAchat.addCell(String.valueOf(achat.getNumDoss())); tableAchat.addCell(achat.getDesignation()); tableAchat.addCell(String.valueOf(achat.getPrix())); } } tableAchat.setSpacingAfter(10); subCatPart.add(tableAchat); //-------------------------- END TAB ACHAT -------------------// // TODO: 20/01/2017 tab composant //-------------------------- TAB COMPOSANT -------------------// PdfPTable tableComp = new PdfPTable(3); tableComp.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableComp.setLockedWidth(true); PdfPCell c4 = new PdfPCell(new Phrase("Composants", catFont)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); c4.setColspan(3); c4.setBorder(Rectangle.NO_BORDER); tableComp.addCell(c4); tableComp.setHeaderRows(1); c4 = new PdfPCell(new Phrase("N.Doss.", dataFont)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); tableComp.addCell(c4); c4 = new PdfPCell(new Phrase("Dsignation", dataFont)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); tableComp.addCell(c4); c4 = new PdfPCell(new Phrase("Quantit", dataFont)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); tableComp.addCell(c4); if (comps.isEmpty()) { c4 = new PdfPCell(new Phrase("la liste des composants est vide", catFontempty)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); c4.setColspan(3); tableComp.addCell(c4); } else { for (Composant comp : comps) { tableComp.addCell(String.valueOf(comp.getNumDoss())); tableComp.addCell(comp.getName()); tableComp.addCell(String.valueOf(comp.getQte())); } } tableComp.setSpacingAfter(10); subCatPart.add(tableComp); //-------------------------- END TAB COMPOSANT -------------------// // TODO: 20/01/2017 tab message //-------------------------- TAB MESSAGE -------------------// PdfPTable tableMsg = new PdfPTable(2); tableMsg.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableMsg.setLockedWidth(true); PdfPCell c5 = new PdfPCell(new Phrase("Message Transmettre", catFont)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); c5.setColspan(3); c5.setBorder(Rectangle.NO_BORDER); tableMsg.addCell(c5); c5 = new PdfPCell(new Phrase("N.Doss.", dataFont)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); tableMsg.addCell(c5); tableMsg.setHeaderRows(1); c5 = new PdfPCell(new Phrase("Message", dataFont)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); tableMsg.addCell(c5); tableMsg.setHeaderRows(1); if (msgs.isEmpty()) { c5 = new PdfPCell(new Phrase("Aucun message", catFontempty)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); c5.setColspan(3); tableMsg.addCell(c5); } else { for (Message msg : msgs) { tableMsg.addCell(String.valueOf(msg.getNumDoss())); tableMsg.addCell(msg.getMsg()); } } tableMsg.setSpacingAfter(10); subCatPart.add(tableMsg); //-------------------------- END TAB MESSAGE -------------------// // TODO: 20/01/2017 tab Activitee //-------------------------- TAB ACTIVITEE -------------------// PdfPTable tableAct = new PdfPTable(2); tableAct.setTotalWidth(PageSize.A4.rotate().getWidth() - 10); tableAct.setLockedWidth(true); PdfPCell c6 = new PdfPCell(new Phrase("Autre Activites", catFont)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); c6.setColspan(2); c6.setBorder(Rectangle.NO_BORDER); tableAct.addCell(c6); tableAct.setHeaderRows(1); c6 = new PdfPCell(new Phrase("N.Doss.", dataFont)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); tableAct.addCell(c6); c6 = new PdfPCell(new Phrase("Dure", dataFont)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); tableAct.addCell(c6); if (autreActs.isEmpty()) { c6 = new PdfPCell(new Phrase("Aucune autre Activite a t effectu", catFontempty)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); c6.setColspan(3); tableAct.addCell(c6); } else { for (Task autreA : autreActs) { tableAct.addCell(String.valueOf(autreA.getType())); tableAct.addCell(autreA.getNumDoss()); } } tableAct.setSpacingAfter(10); subCatPart.add(tableAct); //-------------------------- END TAB MESSAGE -------------------// }
From source file:utils.PrintInvoice.java
public void getDocument() { try {//from w w w .j a v a 2 s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SaleBill#" + salebill.getId() + ".pdf")); document.open(); //////////////////////////////////////////////////////////////////////////////////// ///////////////////Start Document Here///////////////////////////////// PdfContentByte directContent = writer.getDirectContent(); Paragraph p1 = new Paragraph("SALE BILL"); p1.setFont(FONT[4]); p1.setAlignment(Element.ALIGN_CENTER); document.add(p1); //show the company details here. Phrase company = new Phrase(new Chunk("BIO PHARMA\nAKOT 444101(M.S)", FONT[3])); document.add(company); document.add(new Phrase( "\nLicense No : 20B : AK-88888\n 21B : AK-88889\n Mobile : " + SessionClass.getInstance().getMobileNumber(), FONT[2])); // Phrase mobNum = new Phrase(" Mobile : "+SessionClass.getInstance().getMobileNumber() ); // mobNum.setFont(FONT[2]); // ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, mobNum, 35, 710, 0); System.out.println(dateFormatter.format(salebill.getBillDate())); //show the invoice details // String txt = "Bill No. : " + salebill.getId()+"\nBill Date : " + dateFormatter.format(salebill.getBillDate()) +; Phrase invoiceDetails = new Phrase("Bill No. : " + salebill.getId()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 693, 0); invoiceDetails = new Phrase("Bill Date : " + dateFormatter2.format(salebill.getBillDate())); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 681, 0); invoiceDetails = new Phrase("Mode of Payment : " + salebill.getMode()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, invoiceDetails, 400, 668, 0); //show the customer details Customer c = salebill.getCustomerId(); Phrase custDetails = new Phrase("SOLD TO", FONT[3]); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 693, 0); custDetails = new Phrase(c.getCompanyName()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 681, 0); custDetails = new Phrase(c.getSiteAddress()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 668, 0); custDetails = new Phrase("Licence : " + c.getLicenceNo()); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, custDetails, 35, 655, 0); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); //Item Particulars are shown here PdfPTable table = new PdfPTable(7); table.setTotalWidth(new float[] { 175, 80, 80, 50, 50, 50, 75 }); table.setHeaderRows(1); //headers table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell("Particulars"); table.addCell("Batch"); table.addCell("Expiry"); table.addCell("MRP"); table.addCell("Rate"); table.addCell("Qnty"); table.addCell("SubTotal"); table.getDefaultCell().setBackgroundColor(null); table.setSpacingAfter(5.0f); List<SaleBillPharmaItem> items = salebill.getSaleBillPharmaItemList(); for (int i = 0; i < items.size(); i++) { PdfPCell desc = new PdfPCell(new Phrase(items.get(i).getItemName())); table.addCell(desc); PdfPCell batch = new PdfPCell(new Phrase(items.get(i).getBatch())); table.addCell(batch); PdfPCell expiry = null; Date tDate = null; try { tDate = dateFormatter2.parse(items.get(i).getExpDate()); } catch (ParseException ex) { Logger.getLogger(PrintInvoice.class.getName()).log(Level.SEVERE, null, ex); } expiry = new PdfPCell(new Phrase(dateFormatter.format(tDate))); table.addCell(expiry); PdfPCell mrp = new PdfPCell(new Phrase(items.get(i).getMrp() + "")); // //mrp.setBorderColor(BaseColor.WHITE); // mrp.setBorderColorLeft(BaseColor.BLACK); // mrp.setBorderColorRight(BaseColor.WHITE); table.addCell(mrp); PdfPCell rate = new PdfPCell(new Phrase(items.get(i).getItemRate() + "")); // //rate.setBorderColor(BaseColor.WHITE); // rate.setBorderColorLeft(BaseColor.BLACK); // rate.setBorderColorRight(BaseColor.WHITE); table.addCell(rate); PdfPCell quantity = new PdfPCell(new Phrase(items.get(i).getQnty() + "")); // //quantity.setBorderColor(BaseColor.WHITE); // quantity.setBorderColorLeft(BaseColor.BLACK); // quantity.setBorderColorRight(BaseColor.WHITE); table.addCell(quantity); PdfPCell subtotal = new PdfPCell(new Phrase(items.get(i).getAmt() + "")); // //subtotal.setBorderColor(BaseColor.WHITE); // subtotal.setBorderColorLeft(BaseColor.BLACK); // subtotal.setBorderColorRight(BaseColor.WHITE); table.addCell(subtotal); } //now show the sub details //PdfPCell finalCell = new PdfPCell(new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + " Total Amount : Rs ")); //Todo change code here to show vat amount when there is vat number PdfPCell finalCell = new PdfPCell( new Phrase("Total VAT Amt : Rs " + salebill.getTotalVat() + " Total Amount : Rs ")); finalCell.setHorizontalAlignment(Element.ALIGN_RIGHT); finalCell.setColspan(6); table.addCell(finalCell); table.addCell("" + salebill.getTotalAmt()); PdfPCell cdCell = new PdfPCell(new Phrase("Cash Discount (2 %) : (-) Rs")); cdCell.setColspan(6); cdCell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cdCell); table.addCell("" + salebill.getDiscount()); PdfPCell finalAmtCell = new PdfPCell(new Phrase("Final Amount : Rs")); finalAmtCell.setColspan(6); finalAmtCell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(finalAmtCell); table.addCell("" + salebill.getFinalAmt()); document.add(table); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); Paragraph sign = new Paragraph(new Chunk("Authorized signatory\n(BIO PHARMA)")); sign.setAlignment(Element.ALIGN_RIGHT); document.add(sign); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); Paragraph p = new Paragraph("THANK YOU FOR YOUR BUSINESS"); p.setFont(FONT[4]); p.setAlignment(Element.ALIGN_CENTER); document.add(p); ///////////////////End Documnet here////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// document.close(); // no need to close PDFwriter? } catch (DocumentException | FileNotFoundException e) { //LOGGER e.printStackTrace(); Stage dialogStage = new Stage(); dialogStage.setTitle("Printing Error"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.setScene(new Scene(VBoxBuilder.create() .children(new Text( "The file to be printed is already open \n. Please close the file and Print Again")) .alignment(Pos.CENTER).padding(new Insets(50)).build())); dialogStage.show(); } }
From source file:view.PrincipalView.java
public void gerarDocumento() throws IOException, DocumentException { doc = new Document(PageSize.A4.rotate()); String caminho = "C:/RelatoriosAgenda/Ficha.pdf"; PdfWriter.getInstance(doc, new FileOutputStream(caminho)); doc.open();/* w ww .jav a 2 s . co m*/ PdfPTable tabela = new PdfPTable(1); tabela.setHorizontalAlignment(Element.ALIGN_RIGHT); tabela.setWidthPercentage(100f); tabela.setTotalWidth(472); tabela.setLockedWidth(true); Paragraph pNome = new Paragraph("" + tfdNome.getText() + "\n" + tfdSobrenome.getText() + "\n \n"); pNome.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell colNome = new PdfPCell(pNome); tabela.addCell(colNome); doc.add(tabela); JOptionPane.showMessageDialog(null, "Relatrio de Funcionrios salvo com sucesso em C:/RelatoriosAgenda/"); Desktop.getDesktop().open(new File(caminho)); doc.close(); }
From source file:Vista.GenerarPDF.java
private void btngenerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btngenerarActionPerformed String nave = "" + cmbtiponave.getSelectedItem(); String ruta = txtruta.getText(); try {//from w w w .ja va 2 s . com FileOutputStream archivo = new FileOutputStream(ruta + ".pdf"); Document doc = new Document(); PdfWriter.getInstance(doc, archivo); doc.open(); Paragraph parrafo2 = new Paragraph("INFORME DE MANTENIMIENTOS"); parrafo2.setAlignment(1);//el 1 es para centrar doc.add(parrafo2); doc.add(new Phrase(Chunk.NEWLINE)); doc.add(new Phrase(Chunk.NEWLINE)); doc.add(new Paragraph( "Acontinuacion se muestra una lista de los mantenimientos realizados a la aeronave " + nave + "")); doc.add(new Phrase(Chunk.NEWLINE)); PdfPTable tabla = new PdfPTable(6); tabla.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.setTotalWidth(PageSize.A4.getWidth() - 10); //el numero indica la cantidad de Columnas tabla.addCell("ID"); tabla.addCell("Matricula"); tabla.addCell("Estado"); tabla.addCell("Tareas"); tabla.addCell("Fecha inicio"); tabla.addCell("Fecha termino"); tabla.setWidths(new int[] { 1, 2, 4, 4, 3, 3 }); Administrar_Mantenimientos av = new Administrar_Mantenimientos(); ArrayList<Detalle_Mantenimiento> listaMantenimientos = av.listarMantenimientosMatricula(nave); for (int i = 0; i < listaMantenimientos.size(); i++) { tabla.addCell(String.valueOf(listaMantenimientos.get(i).getId())); tabla.addCell(listaMantenimientos.get(i).getMatricula()); tabla.addCell(listaMantenimientos.get(i).getEstado()); tabla.addCell(listaMantenimientos.get(i).getTareas_seleccionadas()); tabla.addCell(listaMantenimientos.get(i).getFecha_inicio()); tabla.addCell(listaMantenimientos.get(i).getFecha_termino()); } // esto nos crea una tabla de 3 Columnas por 2 Filas doc.add(tabla); doc.close(); JOptionPane.showMessageDialog(null, "PDF CREADO CON EXITO"); } catch (Exception e) { System.out.println("error" + e); } }