List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(final float widthPercentage)
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void addSalaryDetails(PdfPTable table, Salary salary) { PdfPTable detailsTable = new PdfPTable(10); detailsTable.setWidthPercentage(100); //*** XML 1 - benefits (multi-add) ************************** if (salary.benefits.length() > 0) { detailsTable.addCell(createSubtitleCell(getTran("web.hr", "benefits"), 10)); // header detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3)); try {/*from ww w . j av a 2s . co m*/ // parse benefits from xml SAXReader reader = new SAXReader(false); org.dom4j.Document document = reader.read(new StringReader(salary.benefits)); org.dom4j.Element benefitsElem = document.getRootElement(); if (benefitsElem != null) { String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount; org.dom4j.Element benefitElem; Iterator benefitsIter = benefitsElem.elementIterator("Benefit"); while (benefitsIter.hasNext()) { benefitElem = (org.dom4j.Element) benefitsIter.next(); sTmpBegin = checkString(benefitElem.elementText("Begin")); sTmpEnd = checkString(benefitElem.elementText("End")); sTmpPeriod = checkString(benefitElem.elementText("Period")); sTmpType = checkString(benefitElem.elementText("Type")); sTmpAmount = checkString(benefitElem.elementText("Amount")); // one benefit detailsTable.addCell(createValueCell(sTmpBegin, 1)); detailsTable.addCell(createValueCell(sTmpEnd, 1)); detailsTable.addCell(createValueCell(getTran("hr.salary.period", sTmpPeriod), 2)); detailsTable.addCell(createValueCell(getTran("hr.salary.benefit.type", sTmpType), 3)); cell = createValueCell( sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); detailsTable.addCell(cell); } } } catch (Exception e) { Debug.printStackTrace(e); } } //*** XML 2 - bonuses (multi-add) ************************** if (salary.bonuses.length() > 0) { table.addCell(createSubtitleCell(getTran("web.hr", "bonuses"), 10)); // header detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 2)); detailsTable.addCell(createHeaderCell(getTran("web", "percentage"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 2)); try { // parse bonuses from xml SAXReader reader = new SAXReader(false); org.dom4j.Document document = reader.read(new StringReader(salary.bonuses)); org.dom4j.Element bonusesElem = document.getRootElement(); if (bonusesElem != null) { String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpPercentage, sTmpAmount; org.dom4j.Element bonusElem; Iterator bonusesIter = bonusesElem.elementIterator("Bonus"); while (bonusesIter.hasNext()) { bonusElem = (org.dom4j.Element) bonusesIter.next(); sTmpBegin = checkString(bonusElem.elementText("Begin")); sTmpEnd = checkString(bonusElem.elementText("End")); sTmpPeriod = checkString(bonusElem.elementText("Period")); sTmpType = checkString(bonusElem.elementText("Type")); sTmpPercentage = checkString(bonusElem.elementText("Percentage")); sTmpAmount = checkString(bonusElem.elementText("Amount")); // one record detailsTable.addCell(createValueCell(sTmpBegin, 1)); detailsTable.addCell(createValueCell(sTmpEnd, 1)); detailsTable.addCell(createValueCell(sTmpPeriod, 2)); detailsTable.addCell(createValueCell(sTmpType, 2)); detailsTable.addCell(createValueCell(sTmpPercentage + "%", 2)); cell = createValueCell( sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 2); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); detailsTable.addCell(cell); } } } catch (Exception e) { Debug.printStackTrace(e); } } //*** XML 3 - otherIncome (multi-add) *********************** if (salary.otherIncome.length() > 0) { table.addCell(createSubtitleCell(getTran("web.hr", "otherIncome"), 10)); // header detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3)); try { // parse otherIncome from xml SAXReader reader = new SAXReader(false); org.dom4j.Document document = reader.read(new StringReader(salary.otherIncome)); org.dom4j.Element benefitsElem = document.getRootElement(); if (benefitsElem != null) { String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount; org.dom4j.Element otherIncomeElem; Iterator otherIncomesIter = benefitsElem.elementIterator("OtherIncome"); while (otherIncomesIter.hasNext()) { otherIncomeElem = (org.dom4j.Element) otherIncomesIter.next(); sTmpBegin = checkString(otherIncomeElem.elementText("Begin")); sTmpEnd = checkString(otherIncomeElem.elementText("End")); sTmpPeriod = checkString(otherIncomeElem.elementText("Period")); sTmpType = checkString(otherIncomeElem.elementText("Type")); sTmpAmount = checkString(otherIncomeElem.elementText("Amount")); // one record detailsTable.addCell(createValueCell(sTmpBegin, 1)); detailsTable.addCell(createValueCell(sTmpEnd, 1)); detailsTable.addCell(createValueCell(sTmpPeriod, 2)); detailsTable.addCell(createValueCell(sTmpType, 3)); cell = createValueCell( sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); detailsTable.addCell(cell); } } } catch (Exception e) { Debug.printStackTrace(e); } } //*** XML 4 - deductions (multi-add) ************************ if (salary.deductions.length() > 0) { detailsTable.addCell(createSubtitleCell(getTran("web.hr", "deductions"), 10)); // header detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3)); try { // parse deductions from xml SAXReader reader = new SAXReader(false); org.dom4j.Document document = reader.read(new StringReader(salary.deductions)); org.dom4j.Element deductionsElem = document.getRootElement(); if (deductionsElem != null) { String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount; org.dom4j.Element deductionElem; Iterator deductionsIter = deductionsElem.elementIterator("Deduction"); while (deductionsIter.hasNext()) { deductionElem = (org.dom4j.Element) deductionsIter.next(); sTmpBegin = checkString(deductionElem.elementText("Begin")); sTmpEnd = checkString(deductionElem.elementText("End")); sTmpPeriod = checkString(deductionElem.elementText("Period")); sTmpType = checkString(deductionElem.elementText("Type")); sTmpAmount = checkString(deductionElem.elementText("Amount")); // one record detailsTable.addCell(createValueCell(sTmpBegin, 1)); detailsTable.addCell(createValueCell(sTmpEnd, 1)); detailsTable.addCell(createValueCell(sTmpPeriod, 2)); detailsTable.addCell(createValueCell(sTmpType, 3)); cell = createValueCell( sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); detailsTable.addCell(cell); } } } catch (Exception e) { Debug.printStackTrace(e); } } if (detailsTable.size() > 0) { table.addCell(emptyCell(3)); cell = createCell(new PdfPCell(detailsTable), table.getNumberOfColumns() - 3, PdfPCell.ALIGN_CENTER, PdfPCell.BOX); cell.setPadding(2); table.addCell(cell); } }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void addWorkscheduleDetails(PdfPTable table, Workschedule schedule) throws Exception { PdfPTable detailsTable = new PdfPTable(10); detailsTable.setWidthPercentage(100); if (schedule.type.equals("day")) displayDaySchedule(detailsTable, schedule); else if (schedule.type.equals("week")) displayWeekSchedule(detailsTable, schedule); else if (schedule.type.equals("month")) displayMonthSchedule(detailsTable, schedule); if (detailsTable.size() > 0) { cell = createCell(new PdfPCell(detailsTable), table.getNumberOfColumns(), PdfPCell.ALIGN_CENTER, PdfPCell.BOX);//from w ww . ja v a2 s.com cell.setPadding(2); table.addCell(cell); } }
From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java
License:Open Source License
protected void buildTitle(Document document) throws DocumentException { //the title is placed in a one-column table of width 100% PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.setWidthPercentage(100f); //one row for the title PdfPCell cell = new PdfPCell(new Phrase(configuration.getTitle(), configuration.getTitleFont())); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingBottom(10f);/* w w w . j av a2 s . c o m*/ table.addCell(cell); //one row for the subtitle cell = new PdfPCell(new Phrase(configuration.getSubtitle(), configuration.getSubtitleFont())); cell.setBorder(Rectangle.NO_BORDER); cell.setBorder(Rectangle.TOP); table.addCell(cell); //make sure that there is some spacing between the title and the scores //20f just seems to work allright, but maybe something more configurable //would be better. table.setSpacingAfter(20f); document.add(table); }
From source file:be.rheynaerde.poolsheets.AbstractPufPoolSheet.java
License:Open Source License
protected PdfPTable getNameTable() { //table with names PdfPTable nameTable = new PdfPTable(1); nameTable.setWidthPercentage(100.0F); nameTable.addCell(getEmptyCell());//ww w. j a v a 2 s. c o m nameTable.addCell(getEmptyCell()); for (int i = 1; i <= getNumberOfPlayers(); i++) { nameTable.addCell(getNameCell(getPlayerName(i))); } return nameTable; }
From source file:beans.CronogramaPDF.java
private void createPdf(String dest) throws IOException, DocumentException, SQLException { Parametrizacion p = new Parametrizacion(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();/* www . ja v a 2 s . c o m*/ PdfPTable table = new PdfPTable(12); BaseColor color = new BaseColor(142, 170, 219); PdfPCell celda; Phrase texto; Font font = new Font(Font.FontFamily.TIMES_ROMAN, 7); Font font1 = new Font(Font.FontFamily.TIMES_ROMAN, 10); table.setWidthPercentage(100); Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png"); celda = new PdfPCell(img, true); celda.setPadding(5); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase( "\n\n\nFecha de creacin: " + dateFormat.format(Calendar.getInstance().getTime()), font1)); celda.setColspan(8); // head.setBackgroundColor(BaseColor.CYAN); table.addCell(celda); celda = new PdfPCell(new Phrase("CRONOGRAMA DE MANTENIMIENTOS", font)); celda.setColspan(112); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("N", font)); celda.setColspan(1); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("CODIGO", font)); celda.setColspan(1); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("FECHA SOLICITUD", font)); celda.setColspan(1); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("EQUIPO", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("ACCIONES A REALIZAR", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); int i = 1; for (SolicitudDeMantenimiento sM : this.solicitudes) { if (!sM.getEstado().equals("Realizada")) { celda = new PdfPCell(new Phrase(i + "", font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase(sM.getCodigo(), font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase(sM.getFecha(), font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase(sM.getEquipo().getNombre(), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(sM.getDescripcionServicio(), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(sM.getDescripcionAcciones(), font)); celda.setColspan(3); table.addCell(celda); i++; } } document.add(table); document.close(); }
From source file:beans.ManagedBeanReportes.java
public void inventario() throws DocumentException, IOException { FacesContext facexcontext = FacesContext.getCurrentInstance(); ValueExpression vex = facexcontext.getApplication().getExpressionFactory() .createValueExpression(facexcontext.getELContext(), "#{managedBeanLogin}", ManagedBeanLogin.class); ManagedBeanLogin beanLogin = (ManagedBeanLogin) vex.getValue(facexcontext.getELContext()); FacesContext context = FacesContext.getCurrentInstance(); Document document = new Document(PageSize.A4, 25, 25, 75, 25);//int marginLeft, int marginRight, int marginTop, int marginBottom ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new ManagedBeanReportes.Watermark("")); if (!document.isOpen()) { document.open();//from www .j a v a 2s. c o m } try { ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext(); //String imageUrl1 = extContext.getRealPath("//resources//images/logo0002.png"); //Image welladigital = Image.getInstance(imageUrl1); //welladigital.setAbsolutePosition(377f, 760f); //welladigital.scalePercent(40); //document.add(welladigital); //crear tabla PARA NOMBRE DEL AO PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.setTotalWidth(450f); // table.setTotalWidth(540f); table.setLockedWidth(true); float[] headerWidths = { 120, 20, 310 }; table.setWidths(headerWidths); table.getDefaultCell(); SimpleDateFormat formato = new SimpleDateFormat("EEEE dd MMMM YYYY"); StringBuilder cadena = new StringBuilder(formato.format(fecha_inicio)); Chunk underline = new Chunk("FECHA DE INVENTARIO:" + cadena.toString().toUpperCase(), bigFont12); underline.setUnderline(0.2f, -2f); //0.1 thick, -2 y-location PdfPCell table5 = new PdfPCell(new Paragraph(underline)); table5.setHorizontalAlignment(Paragraph.ALIGN_CENTER); table5.setColspan(3); table5.setBorder(Rectangle.NO_BORDER); table.addCell(table5); document.add(table); document.add(new Paragraph("\n", pequeFont)); PdfPCell table2 = new PdfPCell(); table2 = new PdfPCell( new Paragraph(beanLogin.getObjetoEmpleado().getTienda().getNombreTienda(), pequeFont)); table2.setHorizontalAlignment(Paragraph.ALIGN_CENTER); table2.setColspan(3); table2.setBorder(Rectangle.NO_BORDER); table = new PdfPTable(3); table.setWidthPercentage(100); table.setTotalWidth(450f); table.setLockedWidth(true); table.setWidths(headerWidths); table.getDefaultCell(); table.addCell(table2); document.add(table); document.add(new Paragraph("\n", pequeFont)); document.add(traerSubtabla(beanLogin.getObjetoEmpleado().getTienda())); formato = new SimpleDateFormat("yyyy-MM-dd"); cadena = new StringBuilder(formato.format(fecha_inicio)); //document.add(traerSubtabla02(cadena.toString())); document.add(new Paragraph("\n", pequeFont)); ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext(); String ctxPath = ((ServletContext) ctx.getContext()).getContextPath(); document.close(); formato = new SimpleDateFormat("dd_MM_yyyy"); cadena = new StringBuilder(formato.format(fecha_inicio)); String fileName = cadena.toString(); writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (Exception de) { de.printStackTrace(); } }
From source file:beans.ManagedBeanReportes.java
public PdfPTable traerSubtabla(Tienda t) throws DocumentException { PdfPTable tabla_PesajeDetalle = new PdfPTable(4); tabla_PesajeDetalle.setWidthPercentage(100); tabla_PesajeDetalle.setTotalWidth(450f); tabla_PesajeDetalle.setLockedWidth(true); tabla_PesajeDetalle.setWidths(anchocol03); tabla_PesajeDetalle.getDefaultCell(); PdfPCell Cell_Headers = new PdfPCell(new Paragraph("PRODUCTO", titulopequeFont)); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("UBICACIONES", titulopequeFont)); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("MINIMO", titulopequeFont)); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("STOCK TOTAL", titulopequeFont)); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); tabla_PesajeDetalle.addCell(Cell_Headers); for (StockProductoTiendaOrigen det : stockProductoTiendaOrigenFacade.lista_stock_tienda(t)) { tabla_PesajeDetalle.addCell(traerCelda(det.getProducto().getNombreProducto())); String ubicaciones_ = ""; for (DetalleAlmacenProductos p : detalleAlmacenProductosFacade.lista_para_stock_tienda(t, det.getProducto())) {// ww w . ja v a 2s .c o m if (p.getUbicacionFisica().getIdUbicacionFisica() > 1) { ubicaciones_ = p.getUbicacionFisica().getNombreUbicacionFisica() + ";" + ubicaciones_; } } tabla_PesajeDetalle.addCell(traerCelda(ubicaciones_)); tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidadMinimaStock()))); tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidad()))); } return tabla_PesajeDetalle; }
From source file:beans.OrdenDeTrabajoPDF.java
private void createPdf(String dest) throws IOException, DocumentException { Parametrizacion p = new Parametrizacion(); this.listaPartes = new JsonParser().parse(ot.getPartes()).getAsJsonArray(); this.listaDescripcionesTrabajos = new JsonParser().parse(ot.getDescripcionesTrabajos()).getAsJsonArray(); this.listaMateriales = new JsonParser().parse(ot.getMateriales()).getAsJsonArray(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();//from w ww. jav a 2 s. c o m PdfPTable table = new PdfPTable(12); BaseColor color = new BaseColor(142, 170, 219); PdfPCell celda; Phrase texto; Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10); table.setWidthPercentage(100); Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png"); celda = new PdfPCell(img, true); celda.setPadding(5); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("ORDEN DE TRABAJO N:" + this.ot.getNumeroOrdenDeTrabajo() + "\nFECHA INICIO:" + this.ot.getFechaInicio() + "\nFECHA FIN:" + this.ot.getFechaFin() + "\nSOLICITUD N:" + this.ot.getSolicitudDeMantenimiento().getCodigo() + "", font)); celda.setColspan(8); // head.setBackgroundColor(BaseColor.CYAN); table.addCell(celda); String tipoSolicitud = ot.getTipoSolicitud(); if (tipoSolicitud.equals("Urgente")) { celda = new PdfPCell(new Phrase("TIPO DE SOLICITUD NORMAL: URGENTE: X", font)); celda.setColspan(12); table.addCell(celda); } else { celda = new PdfPCell(new Phrase("TIPO DE SOLICITUD NORMAL: X URGENTE:", font)); celda.setColspan(12); table.addCell(celda); } if (ot.isDptAdmyControl()) { celda = new PdfPCell(new Phrase( "DTO.ADMS. Y CONTROL DE LA PRODUCCION" + " GENERA ORDEN DE TRABAJO DE MTTO SI:X NO:", font)); celda.setColspan(12); table.addCell(celda); } else { celda = new PdfPCell(new Phrase( "DTO.ADMS. Y CONTROL DE LA PRODUCCION" + " GENERA ORDEN DE TRABAJO DE MTTO SI: NO:X", font)); celda.setColspan(12); table.addCell(celda); } celda = new PdfPCell( new Phrase("CODIGO EQUIPO: " + ot.getSolicitudDeMantenimiento().getEquipo().getCodigo(), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell( new Phrase("NOMBRE EQUIPO: " + ot.getSolicitudDeMantenimiento().getEquipo().getNombre(), font)); celda.setColspan(9); table.addCell(celda); String tipoMantenimiento = ""; for (String element : ot.getTiposDeMantenimiento()) { tipoMantenimiento += element + "\n"; } celda = new PdfPCell(new Phrase("TIPO DE MANTENIMIENTO\n", font)); celda.setColspan(12); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase(tipoMantenimiento, font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("PARTE", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("ANOMALIA", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("CAUSA", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("POSIBLE SOLUCION", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); for (int i = 0; i < listaPartes.size(); i++) { celda = new PdfPCell(new Phrase( listaPartes.get(i).getAsJsonObject().get("parte").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase( listaPartes.get(i).getAsJsonObject().get("anomalia").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase( listaPartes.get(i).getAsJsonObject().get("causa").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase( listaPartes.get(i).getAsJsonObject().get("solucion").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); } celda = new PdfPCell(new Phrase("SOLICTADA POR: " + ot.getSolicitadaPor() + "\n\nFIRMA", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("REVISADA POR: " + ot.getRevisadaPor() + "\n\nFIRMA", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("AUTORIZADA POR: " + ot.getAutorizadaPor() + "\n\nFIRMA", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("N", font)); celda.setColspan(1); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS TRABAJOS A REALIZAR", font)); celda.setColspan(11); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); for (int i = 0; i < listaDescripcionesTrabajos.size(); i++) { celda = new PdfPCell(new Phrase((i + 1) + "", font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase( listaDescripcionesTrabajos.get(i).getAsJsonObject().get("trabajo").toString().replace("\"", ""), font)); celda.setColspan(11); table.addCell(celda); } celda = new PdfPCell(new Phrase("MATERIALES", font)); celda.setColspan(12); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("N", font)); celda.setColspan(1); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("CANTIDAD", font)); celda.setColspan(2); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN", font)); celda.setColspan(3); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("REFERENCIA", font)); celda.setColspan(2); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("VALOR UNI", font)); celda.setColspan(2); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("VALOR TOTAL", font)); celda.setColspan(2); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); for (int i = 0; i < listaMateriales.size(); i++) { celda = new PdfPCell(new Phrase("" + (1 + i), font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("cantidad").toString().replace("\"", ""), font)); celda.setColspan(2); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("descripcion").toString().replace("\"", ""), font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("referencia").toString().replace("\"", ""), font)); celda.setColspan(2); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("unitario").toString().replace("\"", ""), font)); celda.setColspan(2); table.addCell(celda); celda = new PdfPCell(new Phrase( listaMateriales.get(i).getAsJsonObject().get("total").toString().replace("\"", ""), font)); celda.setColspan(2); table.addCell(celda); } celda = new PdfPCell(new Phrase("COSTOS", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("MANO DE OBRA: $" + ot.getCostoManoDeObra() + "", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("MATERIALES: $" + ot.getCostoMateriales() + "", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL: $" + ot.getCostoTotal() + "", font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("TIEMPO EMPLEADO", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + ot.getTotalHorasMto() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + ot.getTotalHorasParada() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS DAOS ENCONTRADOS", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + ot.getDescripcionDanos(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS TRABAJOS REALIZADOS", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + ot.getDescripcionTrabajosRealizados(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("OBSERVACIONES Y RECOMENDACIONES", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + ot.getObservaciones(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("EJECUTO: " + ot.getEjecutadoPor() + "\n\nFIRMA", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("RECIBI Y APROB: " + ot.getRecibidoAprobadoPor() + "\n\nFIRMA", font)); celda.setColspan(6); table.addCell(celda); document.add(table); document.close(); }
From source file:beans.SolicitudDeMantenimientoPDF.java
public void createPdf(String dest) throws IOException, DocumentException { Parametrizacion p = new Parametrizacion(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();/* www . jav a2 s. c o m*/ PdfPTable table = new PdfPTable(12); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell celda; table.setWidthPercentage(100); Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png"); celda = new PdfPCell(img, true); celda.setPadding(5); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("CODIGO: " + sm.getCodigo() + "\nREVISION: " + sm.getRevision() + "\nSOLICITUD DE SERVICIO: " + sm.getSolicitudDeServicio() + "\nFECHA: " + sm.getFecha() + "", font)); celda.setColspan(8); // head.setBackgroundColor(BaseColor.CYAN); table.addCell(celda); celda = new PdfPCell(new Phrase("SECCION", font)); celda.setColspan(4); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("MAQUINA", font)); celda.setColspan(4); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("NOMBRE DEL OPERARIO", font)); celda.setColspan(4); celda.setBackgroundColor(new BaseColor(142, 170, 219)); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getEquipo().getUbicacion(), font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getEquipo().getNombre(), font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getEquipo().getOperario(), font)); celda.setColspan(4); table.addCell(celda); celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); String reparacion = " "; String mtoMecanico = " "; String mtoPreventivo = " "; String mtoElectrico = " "; String mtoCorrectivo = " "; String otros = " "; if (sm.isReparacion()) { reparacion += " X"; } if (sm.isMtoMecanico()) { mtoMecanico += " X"; } if (sm.isMtoPreventivo()) { mtoPreventivo += " X"; } if (sm.isMtoElectrico()) { mtoElectrico += " X"; } if (sm.isMtoCorrectivo()) { mtoCorrectivo += " X"; } if (sm.isOtros()) { otros += " X"; } celda = new PdfPCell(new Phrase("REPARACION", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(reparacion, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("MTO. MECANICO", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(mtoMecanico, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("MTO. PREVENTIVO", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(mtoPreventivo, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("MTO. ELECTRICO", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(mtoElectrico, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("MTO. CORRECTIVO", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(mtoCorrectivo, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("OTROS", font)); celda.setColspan(3); table.addCell(celda); celda = new PdfPCell(new Phrase(otros, font)); celda.setColspan(1); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DEL SERVICIO SOLICITADO", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getDescripcionServicio(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCIN DE ACCIONES A REALIZAR", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getDescripcionAcciones(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("MATERIAL A EMPLEAR", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("" + sm.getMaterial(), font)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("GENERALIDADES", font)); celda.setBackgroundColor(new BaseColor(142, 170, 219)); celda.setColspan(12); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + sm.getHorasParada() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("HORA SOLICITUD: " + sm.getHoraSolicitud() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + sm.getHorasMTO() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("HORA ENTREGA: " + sm.getHoraEntrega() + "", font)); celda.setColspan(6); table.addCell(celda); celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO POR: " + sm.getSolicitadoPor() + "\n" + "SERVICIO REALIZADO POR: " + sm.getRealizadoPor() + "\n" + "RECIBO A CONFORMIDAD: " + sm.getRecibidoPor() + "\n\n\n FIRMA", font)); celda.setColspan(12); table.addCell(celda); document.add(table); document.close(); }
From source file:billerfx.FXMLBillController.java
File generatePDF() { File fi = null;//w w w . j a va2 s . c o m try { Stage gg = ((Stage) imv.getParent().getScene().getWindow()); fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf"); fi.deleteOnExit(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(fi)); Rectangle r = new RectangleReadOnly(207, 575); document.setPageSize(r); document.setMargins(15, 15, 0, 0); document.open(); Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL); Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL); String[] ll = Database.getCurrentSettings(); String ss = "-----------------------------------------------------\n"; ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n"; String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM" : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : ""); ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH)) + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at " + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE) + " " + kk + "\n"; ss += "Table No. " + c.getText() + " Bill No. " + a.getText() + "\n"; ss += "-----------------------------------------------------\n"; Paragraph para = new Paragraph(ss, fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); float[] columnWidths = { 3f, 1f }; table.setWidths(columnWidths); PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); ObservableList ob = map.get(Integer.parseInt(gg.getTitle())); for (int i = 0; i < ob.size(); i++) { Item2 ii = (Item2) ob.get(i); String s1 = ii.getQuantity() + " x " + ii.getName(); String s2 = "Rs. " + ii.getTotal(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(columnWidths); defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); String s1 = "Total:"; String s2 = "Rs. " + h.getText(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) { s1 = "Discount:"; s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText())); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[7].equals("1")) { s1 = ll[3]; s2 = "Rs. " + k.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[8].equals("1")) { s1 = ll[4]; s2 = "Rs. " + l.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } s1 = "Grand Total:"; s2 = "Rs. " + m.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); para = new Paragraph( "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n", fontbold2); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); document.close(); } catch (Exception mm) { } return fi; }