List of usage examples for com.itextpdf.text.pdf PdfPTable setWidths
public void setWidths(final int relativeWidths[]) throws DocumentException
From source file:Clases.NuevoPdf.java
private static void addTableClienteYFactura(Document doc) throws DocumentException { PdfPTable encabezados = new PdfPTable(2); encabezados.setWidthPercentage(99);/*from ww w.j a v a 2s. c o m*/ PdfPCell c1 = new PdfPCell(new Phrase("CLIENTE", normalWhite)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.RED); c1.setBorder(0); encabezados.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("FOLIO FISCAL", normalWhite)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setBackgroundColor(BaseColor.RED); c2.setBorder(0); encabezados.addCell(c2); PdfPTable datos = new PdfPTable(2); datos.setWidthPercentage(99); Paragraph rfc = new Paragraph("N de Folio: " + Variables.idFactura, medium); Paragraph rfc2 = new Paragraph(Variables.RFC, medium); Paragraph nombre = new Paragraph(Variables.NombreCliente, medium); Paragraph direccion = new Paragraph(Variables.delegacion, medium); Paragraph ciudad = new Paragraph(Variables.municipio + " " + Variables.Estado + " MEXICO", medium); Paragraph cp = new Paragraph("CP: " + Variables.codpostal, medium); Paragraph[] datosCliente = { rfc, rfc2, nombre, direccion, ciudad, cp }; PdfPCell c3 = new PdfPCell(); for (int i = 0; i < datosCliente.length; i++) { c3.addElement(datosCliente[i]); } datos.addCell(c3); float[] columnWidths = new float[] { 60f, 40f }; try { encabezados.setWidths(columnWidths); datos.setWidths(columnWidths); } catch (Exception ex) { System.out.println(ex.getMessage()); } Paragraph folioFactura = new Paragraph("CS434-BYOR3343-GVLR03-034", smallBold); Paragraph csd = new Paragraph("No de serie del certificado CSD", smallBold); Paragraph codigo = new Paragraph("03490941023923", smallBold); Paragraph fecha = new Paragraph("Fecha y hora de emisin", smallBold); Paragraph datosfecha = new Paragraph(Variables.FechaSistema, smallBold); folioFactura.setAlignment(Element.ALIGN_CENTER); csd.setAlignment(Element.ALIGN_CENTER); codigo.setAlignment(Element.ALIGN_CENTER); fecha.setAlignment(Element.ALIGN_CENTER); datosfecha.setAlignment(Element.ALIGN_CENTER); Paragraph[] datosFactura = { folioFactura, csd, codigo, fecha, datosfecha }; PdfPCell c4 = new PdfPCell(); for (int i = 0; i < datosFactura.length; i++) { c4.addElement(datosFactura[i]); } datos.addCell(c4); Paragraph p = new Paragraph(); p.add(encabezados); p.add(datos); doc.add(p); }
From source file:Clases.NuevoPdf.java
private static void addTableProducts(Document doc) throws DocumentException { PdfPTable table = new PdfPTable(6); table.setWidthPercentage(99);/*from w ww . ja v a 2s . c o m*/ PdfPCell c1 = new PdfPCell(new Phrase("CLAVE", normalWhite)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setBackgroundColor(BaseColor.RED); c1.setBorder(0); table.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("CANTIDAD", normalWhite)); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setBackgroundColor(BaseColor.RED); c2.setBorder(0); table.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("UM", normalWhite)); c3.setHorizontalAlignment(Element.ALIGN_CENTER); c3.setBackgroundColor(BaseColor.RED); c3.setBorder(0); table.addCell(c3); PdfPCell c4 = new PdfPCell(new Phrase("DESCRIPCION", normalWhite)); c4.setHorizontalAlignment(Element.ALIGN_CENTER); c4.setBackgroundColor(BaseColor.RED); c4.setBorder(0); table.addCell(c4); PdfPCell c5 = new PdfPCell(new Phrase("PRECIO UNITARIO", normalWhite)); c5.setHorizontalAlignment(Element.ALIGN_CENTER); c5.setBackgroundColor(BaseColor.RED); c5.setBorder(0); table.addCell(c5); PdfPCell c6 = new PdfPCell(new Phrase("IMPORTE", normalWhite)); c6.setHorizontalAlignment(Element.ALIGN_CENTER); c6.setBackgroundColor(BaseColor.RED); c6.setBorder(0); table.addCell(c6); float[] columnWidths = new float[] { 15f, 15f, 10f, 30f, 15f, 15f }; try { table.setWidths(columnWidths); } catch (Exception ex) { System.out.println(ex.getMessage()); } for (int i = 0; i < Variables.claves.size(); i++) { table.addCell(new Phrase(String.valueOf(Variables.claves.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.cantidades.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.ums.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.descripciones.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.preciosunitarios.get(i)), normal)); table.addCell(new Phrase(String.valueOf(Variables.importes.get(i)), normal)); } /*table.addCell(new Phrase("R0-510055-TIM",normal)); table.addCell(new Phrase("2.0",normal)); table.addCell(new Phrase("PIEZAS",normal)); table.addCell(new Phrase("BALERO DOBLE",normal)); table.addCell(new Phrase("$336.47",normal)); table.addCell(new Phrase("$672.94",normal));*/ Paragraph p = new Paragraph(); p.add(table); doc.add(p); }
From source file:Clases.NuevoPdf.java
private static void addTableTotales(Document doc) throws DocumentException, IOException { Paragraph totalEnLetras = new Paragraph("SON : SEISCIENTOS SETENTA Y TRES PESOS 52/100 M.N"); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(99);/*from w ww.ja v a 2 s. co m*/ PdfPCell c1 = new PdfPCell(); Paragraph comentariotitulo = new Paragraph("Comentario", smallBold); Paragraph comentario = new Paragraph(Variables.Comentario, small); Paragraph cv = new Paragraph("Condicion de venta: CONTADO", smallBold); Paragraph fp = new Paragraph("Forma de pago: UNA SOLA EXHIBICION", smallBold); Paragraph mp = new Paragraph("Metodo de pago: EFECTIVO", smallBold); Paragraph[] formasPago = { comentariotitulo, comentario, cv, fp, mp }; for (int i = 0; i < formasPago.length; i++) { c1.addElement(formasPago[i]); } c1.setBorder(0); table.addCell(c1); PdfPCell c2 = new PdfPCell(); Paragraph s = new Paragraph("Suma:", small); Paragraph d = new Paragraph("Descuento:", small); Paragraph st = new Paragraph("Subtotal:", small); Paragraph iv = new Paragraph("IVA: 16%:", small); Paragraph t = new Paragraph("Total:", smallBold); Paragraph[] tags = { s, d, st, iv, t }; for (int i = 0; i < tags.length; i++) { c2.addElement(tags[i]); } c2.setBorder(0); table.addCell(c2); PdfPCell c3 = new PdfPCell(); Paragraph ns = new Paragraph("$" + String.valueOf(Variables.suma), small); Paragraph nd = new Paragraph("$" + String.valueOf(Variables.descuento), small); Paragraph nst = new Paragraph("$" + String.valueOf(Variables.subtotal), small); Paragraph niv = new Paragraph("$" + String.valueOf(Variables.iva), small); Paragraph nt = new Paragraph("$" + String.valueOf(Variables.total), smallBold); Paragraph[] totales = { ns, nd, nst, niv, nt }; for (int i = 0; i < totales.length; i++) { c3.addElement(totales[i]); } c3.setBorder(0); table.addCell(c3); float[] columnWidths = new float[] { 66f, 17f, 17f }; try { table.setWidths(columnWidths); } catch (Exception ex) { System.out.println(ex.getMessage()); } Paragraph p = new Paragraph(); Paragraph espaciador = new Paragraph(""); Paragraph sellodigital1 = new Paragraph("Sello digital del CFDI", smallBold); Paragraph sellodigital2 = new Paragraph( "fk0fok0f94kf09fk049fk340fk42f034kf04fk340fi43kf034fk340fk34f034kf034fk340fk340fk34f0o34kf034ofk340fo3k4f03kg35ihjlofkajflakjfl4kfj3l2kfj2f03jgoerkgjsfvns,vmernv034fv349fi2jf034ijf20gfijdqdkqejfoej", small); Paragraph sellodigital3 = new Paragraph("Sello del SAT", smallBold); Paragraph sellodigital4 = new Paragraph( "cmdvkdovewwdqwCWEFRWRVIW3903r930frvDGHERGWRBRVEGRWGWRddkfjdkfrjgkwvnsdlkcmasx,sqpsqlkcwproigkrofik24203940e2932d,swlsk qms12dikd39kdw0oc,wrjbnwepobvkjqevo24f0rwkvwri0bj35ob iwemvlw,amsc,meovkjw0bn0234or0fj", small); Paragraph sellodigital5 = new Paragraph("No de serie del complemento de certificacion del SAT:", smallBold); Paragraph sellodigital6 = new Paragraph("00000100000002133560001", smallBold); Paragraph sellodigital7 = new Paragraph("Fecha y hora de certificacion:", smallBold); Paragraph sellodigital8 = new Paragraph(Variables.FechaFactura, small); Paragraph sellodigital9 = new Paragraph("Expedido en:", smallBold); Paragraph sellodigital10 = new Paragraph("CANCUN, QUINTANA ROO", small); Paragraph sellodigital11 = new Paragraph("ESTE DOCUMENTO ES UNA REPRESENTACION IMPRESA DE UN CFDI ", smallBold); Paragraph[] parrafosSellos = { sellodigital1, sellodigital2, sellodigital3, sellodigital4 }; PdfPTable datosSAT = new PdfPTable(2); datosSAT.setWidthPercentage(99); PdfPCell cS1 = new PdfPCell(new Phrase()); cS1.setHorizontalAlignment(Element.ALIGN_CENTER); cS1.setBorder(0); addLogo(cS1, "qr.jpg"); datosSAT.addCell(cS1); PdfPCell cS2 = new PdfPCell(); for (int i = 0; i < parrafosSellos.length; i++) { cS2.addElement(parrafosSellos[i]); } cS2.setBorder(0); datosSAT.addCell(cS2); float[] columnWidths2 = new float[] { 20f, 80f }; try { datosSAT.setWidths(columnWidths2); } catch (Exception ex) { System.out.println(ex.getMessage()); } p.add(table); p.add(espaciador); p.add(espaciador); p.add(datosSAT); p.add(sellodigital5); p.add(sellodigital6); p.add(sellodigital7); p.add(sellodigital8); p.add(sellodigital9); p.add(sellodigital10); p.add(sellodigital11); doc.add(p); }
From source file:com.asae.controllers.BeanGestionRutinas.java
public void generarPdf() { Document document = new Document(); try {//from w w w .j a v a 2 s . c om File file = File.createTempFile("rutina-", ".pdf", new File("/var/webapp/pdf")); pdfFileName = file.getName(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Font bold = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD); URL url = FacesContext.getCurrentInstance().getExternalContext() .getResource("/resources/img/logo-unicauca-negro.png"); Image imgLogoUnicauca = Image.getInstance(url); imgLogoUnicauca.scaleAbsolute(118f, 131f); PdfPTable tableEncabezado = new PdfPTable(2); tableEncabezado.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEncabezado.setWidthPercentage(100); tableEncabezado.setSpacingAfter(5); PdfPCell cell1 = new PdfPCell(imgLogoUnicauca); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(new Paragraph("Vicerrectoria Administrativa")); cell2.setBorder(Rectangle.NO_BORDER); cell2.setVerticalAlignment(Element.ALIGN_BOTTOM); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); PdfPCell cell3 = new PdfPCell(new Paragraph("Universidad del Cauca", bold)); cell3.setBorder(Rectangle.NO_BORDER); PdfPCell cell4 = new PdfPCell(new Paragraph("Gimnasio y Actividad Fsica", bold)); cell4.setBorder(Rectangle.NO_BORDER); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); tableEncabezado.addCell(cell1); tableEncabezado.addCell(cell2); tableEncabezado.addCell(cell3); tableEncabezado.addCell(cell4); PdfPTable tableDatosUsuario = new PdfPTable(3); tableDatosUsuario.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDatosUsuario.setWidthPercentage(100); tableDatosUsuario.setSpacingBefore(20); PdfPCell cell5 = new PdfPCell(new Paragraph("Nombre: " + rutinaVisualizar.getIdusuario().getFisrtname() + " " + rutinaVisualizar.getIdusuario().getSecondname() + " " + rutinaVisualizar.getIdusuario().getFirstlastname() + " " + rutinaVisualizar.getIdusuario().getSecondlastname())); cell5.setBorder(Rectangle.NO_BORDER); PdfPCell cell6 = new PdfPCell(); cell6.setBorder(Rectangle.NO_BORDER); PdfPCell cell7 = new PdfPCell(); cell7.setBorder(Rectangle.NO_BORDER); tableDatosUsuario.addCell(cell5); tableDatosUsuario.addCell(cell6); tableDatosUsuario.addCell(cell7); PdfPTable tableFechas = new PdfPTable(3); tableFechas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableFechas.setWidthPercentage(100); tableFechas.setSpacingBefore(10); PdfPCell cell8 = new PdfPCell( new Paragraph("Fecha de inicio: " + getMyFormattedDate(rutinaVisualizar.getFechaInicio()))); cell8.setBorder(Rectangle.NO_BORDER); PdfPCell cell9 = new PdfPCell( new Paragraph("Fecha de fin: " + getMyFormattedDate(rutinaVisualizar.getFechaFin()))); cell9.setBorder(Rectangle.NO_BORDER); PdfPCell cell10 = new PdfPCell(); cell10.setBorder(Rectangle.NO_BORDER); tableFechas.addCell(cell8); tableFechas.addCell(cell9); tableFechas.addCell(cell10); PdfPTable tableMedidas = new PdfPTable(4); tableMedidas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableMedidas.setWidthPercentage(100); tableMedidas.setSpacingBefore(10); Usuario usuAux = rutinaVisualizar.getIdusuario(); List<Evaluacion> lstEvalAux = usuAux.getEvaluacionList(); Evaluacion evalAux; double peso = 0; if (lstEvalAux.size() > 0) { evalAux = lstEvalAux.get(lstEvalAux.size() - 1); peso = evalAux.getPeso().doubleValue(); } double estatura = 0; MedidasGenerales medGenAux = usuAux.getMedidasGenerales(); if (medGenAux != null) { estatura = medGenAux.getEstatura().doubleValue(); } PdfPCell cell11 = new PdfPCell(new Paragraph("Peso: " + peso)); cell11.setBorder(Rectangle.NO_BORDER); PdfPCell cell12 = new PdfPCell(new Paragraph("Talla: " + estatura)); cell12.setBorder(Rectangle.NO_BORDER); double imc = 0; if (peso != 0 && estatura != 0) { imc = peso / Math.pow(estatura, 2); } PdfPCell cell13 = new PdfPCell(new Paragraph("I.M.C: " + imc)); cell13.setBorder(Rectangle.NO_BORDER); PdfPCell cell14 = new PdfPCell(new Paragraph("Rutina: " + rutinaVisualizar.getCodigoRutina())); cell14.setBorder(Rectangle.NO_BORDER); tableMedidas.addCell(cell11); tableMedidas.addCell(cell12); tableMedidas.addCell(cell13); tableMedidas.addCell(cell14); PdfPTable tableDias = new PdfPTable(2); tableDias.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDias.setWidthPercentage(100); tableDias.setSpacingBefore(20); tableDias.setHorizontalAlignment(Element.ALIGN_LEFT); tableDias.setWidths(new int[] { 1, 9 }); List<Dia> lstDiasPDF = rutinaVisualizar.getDiaList(); PdfPCell cellCabezeraDia = new PdfPCell(new Paragraph("Da", bold)); PdfPCell cellCabezeraDia2 = new PdfPCell(); cellCabezeraDia2.setBorder(Rectangle.NO_BORDER); tableDias.addCell(cellCabezeraDia); tableDias.addCell(cellCabezeraDia2); for (Dia dia : lstDiasPDF) { PdfPCell cellDia = new PdfPCell(new Paragraph(dia.getNumDia().toString())); PdfPCell cellDia2 = new PdfPCell(); cellDia2.setBorder(Rectangle.NO_BORDER); List<GrupoMuscular> lstGMuscularPDF = dia.getGrupoMuscularList(); if (lstGMuscularPDF.size() > 0) { PdfPTable tableGMuscular = new PdfPTable(2); tableGMuscular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableGMuscular.setWidthPercentage(100); tableGMuscular.setHorizontalAlignment(Element.ALIGN_LEFT); tableGMuscular.setWidths(new int[] { 1, 6 }); PdfPCell cellCabezeraGMuscular = new PdfPCell(new Paragraph("Grupo Muscular", bold)); cellCabezeraGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); PdfPCell cellCabezeraGMuscular2 = new PdfPCell(); cellCabezeraGMuscular2.setBorder(Rectangle.NO_BORDER); tableGMuscular.addCell(cellCabezeraGMuscular); tableGMuscular.addCell(cellCabezeraGMuscular2); int aux = 1; for (GrupoMuscular gMuscularFor : lstGMuscularPDF) { PdfPCell cellGMuscular = new PdfPCell( new Paragraph(gMuscularFor.getIdgrupoMuscularGeneral().getNombre())); cellGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); PdfPCell cellGMuscular2 = new PdfPCell(); cellGMuscular2.setBorder(Rectangle.NO_BORDER); List<EjercicioGm> lstEjerciciosGMuscularPDF = gMuscularFor.getEjercicioGmList(); BaseColor myColor = WebColors.getRGBColor("#CCEEFF"); if (lstEjerciciosGMuscularPDF.size() > 0) { PdfPTable tableEjercicioGMsucular = new PdfPTable(5); tableEjercicioGMsucular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEjercicioGMsucular.setWidthPercentage(100); tableEjercicioGMsucular.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cellCabezeraEjercicioGM = new PdfPCell(new Paragraph("Ejercicio", bold)); cellCabezeraEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM.setLeading(20f, 0f); cellCabezeraEjercicioGM.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM); PdfPCell cellCabezeraEjercicioGM2 = new PdfPCell(new Paragraph("Series", bold)); cellCabezeraEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM2.setLeading(20f, 0f); cellCabezeraEjercicioGM2.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM2); PdfPCell cellCabezeraEjercicioGM3 = new PdfPCell(new Paragraph("Repeticiones", bold)); cellCabezeraEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM3.setLeading(20f, 0f); cellCabezeraEjercicioGM3.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM3); PdfPCell cellCabezeraEjercicioGM4 = new PdfPCell(new Paragraph("Receso", bold)); cellCabezeraEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM4.setLeading(20f, 0f); cellCabezeraEjercicioGM4.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM4); PdfPCell cellCabezeraEjercicioGM5 = new PdfPCell(new Paragraph("Peso", bold)); cellCabezeraEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM5.setLeading(20f, 0f); cellCabezeraEjercicioGM5.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM5); int aux2 = 1; for (EjercicioGm ejercicioGm : lstEjerciciosGMuscularPDF) { PdfPCell cellEjercicioGM = new PdfPCell( new Paragraph(ejercicioGm.getEjercicio().getNombre())); cellEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM.setLeading(20f, 0f); PdfPCell cellEjercicioGM2 = new PdfPCell( new Paragraph(ejercicioGm.getNumeroSeries().toString())); cellEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM2.setLeading(20f, 0f); PdfPCell cellEjercicioGM3 = new PdfPCell( new Paragraph(ejercicioGm.getRepeticiones().toString())); cellEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM3.setLeading(20f, 0f); PdfPCell cellEjercicioGM4 = new PdfPCell( new Paragraph(ejercicioGm.getReceso().toString())); cellEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM4.setLeading(20f, 0f); PdfPCell cellEjercicioGM5 = new PdfPCell( new Paragraph(ejercicioGm.getPeso().toString())); cellEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM5.setLeading(20f, 0f); if (aux2 % 2 == 0) { cellEjercicioGM.setBackgroundColor(myColor); cellEjercicioGM2.setBackgroundColor(myColor); cellEjercicioGM3.setBackgroundColor(myColor); cellEjercicioGM4.setBackgroundColor(myColor); cellEjercicioGM5.setBackgroundColor(myColor); } tableEjercicioGMsucular.addCell(cellEjercicioGM); tableEjercicioGMsucular.addCell(cellEjercicioGM2); tableEjercicioGMsucular.addCell(cellEjercicioGM3); tableEjercicioGMsucular.addCell(cellEjercicioGM4); tableEjercicioGMsucular.addCell(cellEjercicioGM5); aux2++; } cellGMuscular2.addElement(tableEjercicioGMsucular); } tableGMuscular.addCell(cellGMuscular); tableGMuscular.addCell(cellGMuscular2); aux++; } cellDia2.addElement(tableGMuscular); } tableDias.addCell(cellDia); tableDias.addCell(cellDia2); } LineSeparator ls = new LineSeparator(); document.add(tableEncabezado); document.add(ls); document.add(tableDatosUsuario); document.add(tableFechas); document.add(tableMedidas); document.add(tableDias); document.close(); } catch (DocumentException | FileNotFoundException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(BeanGestionRutinas.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
private void createTable(Document document) throws DocumentException, MalformedURLException, IOException { PdfPTable table = new PdfPTable(8); table.setWidths(new int[] { 5, 10, 30, 15, 15, 15, 25, 20 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); // addLogo(table); String[] headerTitle = { "Sl", "Qty", "Medicine Name", "Mfg Date", "Batch", "Exp Date", "Schedule", "Price" }; Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD); for (String header : headerTitle) { Phrase p = new Phrase(header, headerFont); PdfPCell c1 = new PdfPCell(p); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setLeading(0f, 1.5f);//from w w w . j a v a 2s . c om c1.setBackgroundColor(BaseColor.GRAY); table.addCell(c1); } Font contentFont = new Font(Font.FontFamily.TIMES_ROMAN, 9f); MedicineUtility mUtil = new MedicineUtility(); // table.setSpacingAfter(20); double vat = 0.0; double discount = 0.0; int count = 1; double totalAmt = 0.0; if (totalRecords != null && totalRecords.size() > 0) { for (InvoiceBean iBean : totalRecords) { // replaceDoctor = iBean.getDoctorName(); // replaceCustomer = iBean.getCustomerName(); // replaceCustAddr1 = iBean.getCustomerAddr1(); // replaceBillNo = iBean.getBillNo(); // replaceBillDate = iBean.getPurchaseDate(); vat = iBean.getVat(); discount = iBean.getDiscount(); PdfPCell c = new PdfPCell(new Phrase(count++ + "", contentFont)); table.addCell(c); c = new PdfPCell(new Phrase(iBean.getSoldoutStock() + "", contentFont)); table.addCell(c); table.addCell(new PdfPCell(new Phrase(iBean.getMedicineName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getMfgDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getBatchName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getExpDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getSchedule(), contentFont))); totalAmt = totalAmt + (iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice()); table.addCell(new PdfPCell(new Phrase( mUtil.getFormattedAmount((iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice())), contentFont))); } } double grandTotal = 0.0; // Total PdfPCell c1 = new PdfPCell(new Phrase("Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(totalAmt))); c1.setColspan(1); table.addCell(c1); // Vat c1 = new PdfPCell(new Phrase("Vat(" + vat + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double vatAmt = totalAmt * vat / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(vatAmt))); c1.setColspan(1); table.addCell(c1); // Discount c1 = new PdfPCell(new Phrase("Discount(" + discount + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double discountAmt = totalAmt * discount / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(discountAmt))); c1.setColspan(1); table.addCell(c1); // Grand Total c1 = new PdfPCell(new Phrase("Grand Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); grandTotal = (totalAmt + vatAmt - discountAmt); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(grandTotal))); c1.setColspan(1); table.addCell(c1); document.add(table); }
From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java
License:Apache License
/** * header ? footer // ww w . j a va2 s . c om */ public void onEndPage(PdfWriter writer, Document document) { if (titleFlag) return; Font font = new Font(bfKorean, 9); PdfPTable hTable = new PdfPTable(1); PdfPTable ftable = new PdfPTable(3); try { hTable.setWidths(new int[] { 100 }); hTable.setTotalWidth(500); hTable.setLockedWidth(true); hTable.getDefaultCell().setFixedHeight(15); hTable.getDefaultCell().setBorder(Rectangle.BOTTOM); hTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); hTable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.header.title"), font)); hTable.writeSelectedRows(0, -1, 50, 803, writer.getDirectContent()); ftable.setWidths(new int[] { 100, 100, 100 }); ftable.setTotalWidth(500); ftable.setLockedWidth(true); ftable.getDefaultCell().setBorder(Rectangle.TOP); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); ftable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.footer.left"), font)); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); if (pagingFlag) ftable.addCell(new Phrase( MessageUtil.getMessage("pdf.message.footer.center", String.valueOf(writer.getPageNumber())), font)); else ftable.addCell(""); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); ftable.addCell(new Phrase(String.valueOf(new SimpleDateFormat("yyyy/MM/dd").format(new Date())), font)); ftable.writeSelectedRows(0, -1, 50, 55, writer.getDirectContent()); } catch (Exception de) { throw new ExceptionConverter(de); } }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * /*from ww w .ja v a 2 s . co m*/ * PDF Title Page * * @param doc * @param writer */ public static void setTitleMainPage(Document doc, PdfWriter writer, PDFCommonEventHelper event, Upload upload) throws Exception { Font fnTitle = new Font(bfKorean, 20, Font.BOLD); Font fnLabel = new Font(bfKorean, 11, Font.BOLD); Font fnText = new Font(bfKorean, 11); LineSeparator UNDERLINE = new LineSeparator(1, 80, null, com.itextpdf.text.Element.ALIGN_CENTER, -5); doc.newPage(); doc.add(Chunk.NEWLINE); event.setTitleFlag(true); int toc = writer.getPageNumber(); Image img = Image.getInstance(PDFDocGenerator.class.getResource("/image/title.gif")); img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); img.scalePercent(80, 80); doc.add(img); Paragraph titlePh = new Paragraph(MessageUtil.getMessage("pdf.message.main.title"), fnTitle); titlePh.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); titlePh.setSpacingBefore(50); titlePh.setSpacingAfter(30); doc.add(titlePh); doc.add(UNDERLINE); PdfPTable t1 = new PdfPTable(2); t1.setSpacingBefore(20); t1.setWidths(new int[] { 110, 290 }); t1.getDefaultCell().setBorder(0); t1.getDefaultCell().setFixedHeight(32); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_name"), fnLabel)); t1.addCell(new Phrase(upload.getProjectNm(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.department"), fnLabel)); t1.addCell(new Phrase(upload.getDepartment(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.focus_name"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.focus_name"), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.product"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.product", upload.getBeforeWas(), upload.getAfterWas()), fnText)); doc.add(t1); doc.add(UNDERLINE); Paragraph executedPh = new Paragraph(MessageUtil.getMessage("pdf.message.main.label.executed"), fnLabel); executedPh.setSpacingBefore(30); executedPh.setSpacingAfter(15); executedPh.setIndentationLeft(50); doc.add(executedPh); PdfPTable t2 = new PdfPTable(2); t2.getDefaultCell().setFixedHeight(28); t2.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); t2.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.owner"), fnLabel)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_role"), fnLabel)); t2.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); t2.addCell(new Phrase(upload.getPerson(), fnText)); t2.addCell(new Phrase(upload.getOrgRole(), fnText)); doc.add(t2); doc.newPage(); int total = writer.reorderPages(null); int[] order = new int[total]; for (int i = 0; i < total; i++) { order[i] = i + toc; if (order[i] > total) order[i] -= total; } // apply the new order writer.reorderPages(order); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * /*from w w w . j av a 2s. c om*/ * ?? header * * @param e table element * @param t header table ? * @param colCount column * @throws Exception */ public static void setTableHeader(Element e, PdfPTable t, int colCount) throws Exception { t.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); ArrayList<Integer> colWidth = new ArrayList<Integer>(); for (Element e1 : e.getChild("header").getChildren()) { t.addCell(new Phrase(e1.getText(), fnNormalBold)); if (e1.getAttributeValue("width") != null) colWidth.add(Integer.parseInt(e1.getAttributeValue("width"))); } if (colCount == colWidth.size()) { int[] col = new int[colCount]; for (int i = 0; i < colCount; i++) col[i] = colWidth.get(i); t.setWidths(col); } }
From source file:com.automaster.autoview.server.servlet.TableHeader.java
/** * Adds a header to every page/*from w ww.j a v a 2s . c o m*/ * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(3); try { table.setWidths(new int[] { 24, 24, 2 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.addCell(header); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Pgina %d de", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.BOTTOM); table.addCell(cell); table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private void writeDocument(Document document, File targetFile) { boolean frame = detailTabfolder.getSelectionIndex() == 1; try (FileOutputStream out = new FileOutputStream(targetFile)) { PdfWriter writer = PdfWriter.getInstance(document, out); document.open();// w w w . j a va 2s .c o m writer.setPageEvent(new PdfPageEventHelper() { int pageNo = 0; com.itextpdf.text.Font ffont = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 9, com.itextpdf.text.Font.NORMAL, BaseColor.DARK_GRAY); @Override public void onEndPage(PdfWriter w, Document d) { PdfContentByte cb = w.getDirectContent(); Phrase footer = new Phrase(String.valueOf(++pageNo), ffont); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom(), 0); } }); String tit = NLS.bind(Messages.ExhibitionEditDialog_exhibition_name, nameField.getText()); Paragraph p = new Paragraph(tit, FontFactory.getFont(FontFactory.HELVETICA, 14, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(8); document.add(p); String subtitle = NLS.bind(Messages.ExhibitionEditDialog_image_list, Constants.DFDT.format(new Date()), frame ? Messages.ExhibitionEditDialog_image_sizes : Messages.ExhibitionEditDialog_frame_sizes); p = new Paragraph(subtitle, FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(14); document.add(p); p = new Paragraph(descriptionField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); p = new Paragraph(infoField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); IDbManager db = Core.getCore().getDbManager(); List<Wall> walls = current.getWall(); Wall[] sortedWalls = walls.toArray(new Wall[walls.size()]); Arrays.sort(sortedWalls, new Comparator<Wall>() { public int compare(Wall o1, Wall o2) { return o1.getLocation().compareToIgnoreCase(o2.getLocation()); } }); for (Wall wall : sortedWalls) { p = new Paragraph(wall.getLocation(), FontFactory.getFont(FontFactory.HELVETICA, 12, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(12); document.add(p); PdfPTable table = new PdfPTable(7); // table.setBorderWidth(1); // table.setBorderColor(new Color(224, 224, 224)); // table.setPadding(5); // table.setSpacing(0); table.setWidths(new int[] { 8, 33, 13, 13, 20, 13, 20 }); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_No, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_title, Element.ALIGN_LEFT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_xpos, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_height, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_size, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_dpi, Element.ALIGN_RIGHT)); table.addCell(createTableHeader("", Element.ALIGN_LEFT)); //$NON-NLS-1$ // table.endHeaders(); List<ExhibitImpl> exhibits = new ArrayList<ExhibitImpl>(); for (String exhibitId : wall.getExhibit()) { ExhibitImpl exhibit = db.obtainById(ExhibitImpl.class, exhibitId); if (exhibit != null) exhibits.add(exhibit); } Collections.sort(exhibits, new Comparator<ExhibitImpl>() { public int compare(ExhibitImpl e1, ExhibitImpl e2) { return ((Exhibit) e1).getX() - ((Exhibit) e2).getX(); } }); int no = 1; for (ExhibitImpl exhibit : exhibits) { int tara = computeTara(frame, exhibit); table.addCell(createTableCell(String.valueOf(no++), Element.ALIGN_RIGHT)); table.addCell(createTableCell(exhibit.getTitle(), Element.ALIGN_LEFT)); af.setMaximumFractionDigits(2); af.setMinimumFractionDigits(2); String x = af.format((exhibit.getX() - tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", x), Element.ALIGN_RIGHT)); //$NON-NLS-1$ String y = af.format((exhibit.getY() + tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", y), Element.ALIGN_RIGHT)); //$NON-NLS-1$ af.setMaximumFractionDigits(1); af.setMinimumFractionDigits(1); String h = af.format((exhibit.getHeight() + 2 * tara) / 10d); int width = exhibit.getWidth(); String w = af.format((width + 2 * tara) / 10d); table.addCell(createTableCell(NLS.bind("{0} x {1} cm", w, h), Element.ALIGN_RIGHT)); //$NON-NLS-1$ AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset()); if (asset != null) { int pixels = asset.getWidth(); double dpi = pixels * 25.4d / width; table.addCell(createTableCell(String.valueOf((int) dpi), Element.ALIGN_RIGHT)); } else table.addCell(""); //$NON-NLS-1$ table.addCell(createTableCell(exhibit.getSold() ? Messages.ExhibitionEditDialog_sold : "", //$NON-NLS-1$ Element.ALIGN_LEFT)); } document.add(table); } document.close(); } catch (DocumentException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_internal_error_writing_pdf, e); } catch (IOException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_io_error_writing_pdf, e); } }