List of usage examples for com.lowagie.text.pdf PdfPTable setLockedWidth
public void setLockedWidth(boolean lockedWidth)
setTotalWidth()
in Document.add()
. From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java
License:Open Source License
public static PdfPTable createTable2(LinkedList<String[]> laborBlatt) throws DocumentException, IOException { int noOfCols = laborBlatt.get(0)[0].length(); PdfPTable table = new PdfPTable(noOfCols); float[] colWidths = new float[noOfCols]; colWidths[0] = 200f;/* w ww. j av a 2 s . co m*/ for (int i = 1; i < colWidths.length; i++) { colWidths[i] = 40f; } table.setTotalWidth(colWidths); table.setLockedWidth(true); // the cell object PdfPCell cell; for (String[] strings : laborBlatt) { for (int i = 0; i < strings.length; i++) { System.out.print(i + ":" + strings[i]); cell = new PdfPCell(new Phrase(strings[i], fontTimesSmall)); cell.setUseBorderPadding(true); // // Setting cell's border width and color // cell.setBorderWidth(0.5f); table.addCell(cell); } //System.out.println("----------"); //System.out.println(); } // we add a cell with colspan 3 return table; }
From source file:com.prime.location.billing.InvoicedBillingManager.java
/** * Print invoice//from ww w.j a v a2 s. c o m */ public void printInvoice() { try { //catch better your exceptions, this is just an example FacesContext context = FacesContext.getCurrentInstance(); Document pdf = new Document(PageSize.A4, 5f, 5f, 75f, 45f); String fileName = "PDFFile"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(pdf, baos); TableHeader event = new TableHeader(); event.setHeader("Header Here"); writer.setPageEvent(event); if (!pdf.isOpen()) { pdf.open(); } PdfPCell cell; PdfPTable header = new PdfPTable(new float[] { 1, 2, 1 }); cell = new PdfPCell(new Paragraph("INVOICE", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC, Color.BLACK))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); header.setTotalWidth(527); header.setLockedWidth(true); cell = new PdfPCell(new Phrase("Agency: " + selectedAgency.getDescription())); cell.setColspan(2); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); cell = new PdfPCell(new Phrase("Invoice#: " + selectedInvoice.getId())); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); cell = new PdfPCell( new Phrase("Date: " + DateUtility.dateTimeFormat(selectedInvoice.getInvoiceDate()))); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); pdf.add(header); PdfPTable table = new PdfPTable(new float[] { 1, 3, 2, 1 }); table.setSpacingBefore(15f); table.setTotalWidth(527); table.setLockedWidth(true); //table.setWidths(new int[]{3, 1, 1}); table.getDefaultCell().setBackgroundColor(Color.LIGHT_GRAY); table.addCell("Date"); table.addCell("Name"); table.addCell("Service"); table.addCell("Rate"); table.getDefaultCell().setBackgroundColor(null); cell = new PdfPCell(new Phrase("Total(US$): ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setColspan(3); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(selectedInvoice.getAmount()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); // There are three special rows table.setHeaderRows(2); // One of them is a footer table.setFooterRows(1); Font f = FontFactory.getFont(FontFactory.HELVETICA, 10); //add remaining for (AgencyBilling billing : selectedInvoice.getBillings()) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setIndent(2); table.getDefaultCell().setFixedHeight(20); table.addCell(new Phrase(DateUtility.dateFormat(billing.getBillingDate()), f)); table.addCell(new Phrase(billing.getPerson().getName(), f)); table.addCell(new Phrase(billing.getTariff().getTariffType().getDescription(), f)); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(billing.getRate()), f)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } pdf.add(table); writer.getAcroForm().setNeedAppearances(true); //document.add(new Phrase(TEXT)); //Keep modifying your pdf file (add pages and more) pdf.close(); writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (Exception e) { //e.printStackTrace(); } }
From source file:com.prime.report.template.TableHeader.java
/** * Adds a header to every page/*from w w w .ja v a 2 s .co m*/ * * @param writer * @param document * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(4); try { table.setWidths(new int[] { 10, 11, 9, 1 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); Image img = Image.getInstance(logo); table.addCell(Image.getInstance(img)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase("New South West Facility Center", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, Color.BLACK))); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Page %d of", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } catch (IOException ex) { Logger.getLogger(TableHeader.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.tsp.gespro.bo.DegustacionBO.java
/** * Representacin impresa PDF//w w w . ja va 2s . c om */ public ByteArrayOutputStream toPdf(UsuarioBO user) throws Exception { SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat hora = new SimpleDateFormat("HH:mm:ss"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfITextUtil obj = new PdfITextUtil(); //Tamao de documento (Tamao Carta) com.lowagie.text.Document doc = new com.lowagie.text.Document(PageSize.LETTER); //Definicin de Fuentes a usar Font letraOcho = new Font(Font.HELVETICA, 8, Font.NORMAL); Font letraOchoBold = new Font(Font.HELVETICA, 8, Font.BOLD); Font letraNueve = new Font(Font.HELVETICA, 9, Font.NORMAL); Font letraNueveBold = new Font(Font.HELVETICA, 9, Font.BOLD); Font letraNueveBoldRojo = new Font(Font.TIMES_ROMAN, 9, Font.BOLD, Color.red); Font letraNueveBoldAzul = new Font(Font.TIMES_ROMAN, 9, Font.BOLD, Color.blue); Font letraOchoVerde = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL, Color.green); Font letra14Bold = new Font(Font.HELVETICA, 14, Font.BOLD); String msgError = ""; File fileImageLogo = null; try { if (user != null) fileImageLogo = new ImagenPersonalBO(this.conn) .getFileImagenPersonalByEmpresa(user.getUser().getIdEmpresa()); } catch (Exception ex) { ex.printStackTrace(); } try { //Preparamos writer de PDF PdfWriter writer = PdfWriter.getInstance(doc, baos); EventPDF eventPDF = new EventPDF(doc, user, ReportBO.DEGUSTACION_REPRESENTACION_IMPRESA, fileImageLogo); writer.setPageEvent(eventPDF); //Ajustamos margenes de pgina //doc.setMargins(50, 50, 120, 50); //doc.setMargins(20, 20, 80, 20); doc.setMargins(10, 10, 150, 40); //Iniciamos documento doc.open(); //Creamos tabla principal PdfPTable mainTable = new PdfPTable(1); mainTable.setTotalWidth(550); mainTable.setLockedWidth(true); //CONTENIDO ------------- //SALTO DE L?NEA obj.agregaCelda(mainTable, letraOcho, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); //Cabecera (Datos Generales)--------------------- PdfPTable tAux = new PdfPTable(1); Cliente clienteDto = null; DatosUsuario datosUsuarioVendedor = null; try { if (this.degustacion.getIdCliente() > 0) clienteDto = new ClienteBO(this.degustacion.getIdCliente(), this.conn).getCliente(); if (this.degustacion.getIdUsuario() > 0) datosUsuarioVendedor = new UsuarioBO(this.degustacion.getIdUsuario()).getDatosUsuario(); } catch (Exception ex) { ex.printStackTrace(); } //Datos informativos generales PdfPTable tInfoGeneral = new PdfPTable(1); tInfoGeneral.setTotalWidth(160); tInfoGeneral.setLockedWidth(true); obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "ID Degustacin", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueveBoldRojo, "" + this.degustacion.getIdDegustacion(), new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "Fecha Degustacin", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueve, DateManage.dateToStringEspanol(this.degustacion.getFechaApertura()), new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "Promotor", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(tInfoGeneral, letraNueve, datosUsuarioVendedor != null ? (datosUsuarioVendedor.getNombre() + " " + datosUsuarioVendedor.getApellidoPat()) : "Sin vendedor asignado", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); //Pintamos datos informativos Generales en la esquina superior derecha PdfContentByte cb = writer.getDirectContent(); tInfoGeneral.writeSelectedRows(0, -1, doc.right() - 180, doc.top() + 100, cb); //Datos de Cliente/Prospecto PdfPTable tCliente = new PdfPTable(2); tCliente.setTotalWidth(550); tCliente.setLockedWidth(true); obj.agregaCelda(tCliente, letraNueveBold, Color.lightGray, "Cliente", new boolean[] { false, false, false, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 2); tAux = new PdfPTable(1); tAux.setTotalWidth(275); tAux.setLockedWidth(true); try { obj.agregaCelda(tAux, letraOcho, "Nombre Comercial: " + (clienteDto != null ? clienteDto.getNombreComercial() : ""), new boolean[] { false, true, false, false }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0, new int[0], 1); } catch (Exception ex) { ex.printStackTrace(); } obj.agregaTabla(tCliente, tAux, new boolean[] { false, false, false, false }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0, new int[0], 1); obj.agregaCelda(tCliente, letraOcho, "" + "DOMICILIO: \n" + (clienteDto != null ? "Calle: " + clienteDto.getCalle() : "") + " " + (clienteDto != null ? clienteDto.getNumero() : "") + " " + (clienteDto != null ? clienteDto.getNumeroInterior() : "") + (clienteDto != null ? " Col: " + clienteDto.getColonia() : "") + (clienteDto != null ? " \nDeleg./Municipio: " + clienteDto.getMunicipio() : "") + (clienteDto != null ? " Estado: " + clienteDto.getEstado() : "") + (clienteDto != null ? " \nC.P. " + clienteDto.getCodigoPostal() : ""), new boolean[] { false, true, false, true }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0, new int[0], 1); obj.agregaTabla(mainTable, tCliente, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1); //FIN Cabecera (Datos Generales)----------------- //DOBLE SALTO DE L?NEA obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); int colsDetalles = 6; PdfPTable tDetalles = new PdfPTable(colsDetalles);//6); tDetalles.setTotalWidth(550); tDetalles.setWidths(new int[] { 200, 70, 70, 70, 70, 70 }); tDetalles.setLockedWidth(true); /*CABECERA*/ obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Producto Degustado", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Hr Inicio", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Hr Termino", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Inventario Inicial", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Inventario Final", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Piezas Degustadas", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); /*FIN DE CABECERA*/ Degustacion[] degustacionDtos = new Degustacion[0]; try { degustacionDtos = this.findDegustaciones(this.degustacion.getIdDegustacion(), this.degustacion.getIdEmpresa(), -1, -1, ""); } catch (Exception e) { } //Listado de Productos for (Degustacion item : degustacionDtos) { if (item != null) { Concepto conceptoDto = null; try { ConceptoBO conceptoBO = new ConceptoBO(item.getIdConcepto(), this.conn); conceptoDto = conceptoBO.getConcepto(); } catch (Exception e) { } //Producto obj.agregaCelda(tDetalles, letraOcho, null, conceptoDto.getNombreDesencriptado(), new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Inicio obj.agregaCelda(tDetalles, letraOcho, null, hora.format(item.getFechaApertura()), new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Termino obj.agregaCelda(tDetalles, letraOcho, null, hora.format(item.getFechaCierre()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Inv inicial obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidad()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //inv final obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidadCierre()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Piezas obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidad() - item.getCantidadCierre()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); } } obj.agregaTabla(mainTable, tDetalles, new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1); //DOBLE SALTO DE L?NEA obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); /*prods Vendidos durante degustacion*/ PdfPTable tVenta = new PdfPTable(4); tVenta.setTotalWidth(550); tVenta.setWidths(new int[] { 70, 140, 170, 120 }); tVenta.setLockedWidth(true); obj.agregaCelda(tVenta, letraNueveBold, Color.lightGray, "Producto Vendido durante Degutacin", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 4); Productosvendidos[] pedidoProductoDto = new Productosvendidos[0]; String filtroBusqueda = " ID_PEDIDO IN ( SELECT ID_PEDIDO FROM sgfens_pedido WHERE ID_EMPRESA = '" + this.degustacion.getIdEmpresa() + "' AND ID_TIPO_PEDIDO = 2 AND ID_USUARIO_VENDEDOR = " + this.degustacion.getIdUsuario() + " AND " + " ID_ESTATUS_PEDIDO<>2 AND FECHA_PEDIDO BETWEEN '" + this.degustacion.getFechaApertura() + "' AND '" + this.degustacion.getFechaCierre() + "') "; try { pedidoProductoDto = new ProductosvendidosDaoImpl().findByDynamicWhere(filtroBusqueda, null); } catch (Exception e) { } if (pedidoProductoDto.length > 0) { obj.agregaCelda(tVenta, letraOchoBold, null, "Cdigo", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tVenta, letraOchoBold, null, "Nombre", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tVenta, letraOchoBold, null, "Descripcin", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); obj.agregaCelda(tVenta, letraOchoBold, null, "Unidades Vendidas", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1); for (Productosvendidos pedidoProd : pedidoProductoDto) { if (pedidoProd != null) { Concepto conceptoDto = null; try { ConceptoBO conceptoBO = new ConceptoBO(pedidoProd.getIdConcepto(), this.conn); conceptoDto = conceptoBO.getConcepto(); } catch (Exception e) { } //Cdigo obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getIdentificacion(), new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Nombre obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getNombreDesencriptado(), new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Descripcin obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getDescripcion(), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); //Unidades Vendidas obj.agregaCelda(tVenta, letraOcho, null, "" + (pedidoProd.getCantidad()), new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1); } } } else { obj.agregaCelda(tVenta, letraOcho, null, "No se registrarn datos.", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 4); } obj.agregaTabla(mainTable, tVenta, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1); //DOBLE SALTO DE L?NEA obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1); /*Comentarios Adicionales*/ PdfPTable tComenst = new PdfPTable(1); tComenst.setTotalWidth(550); tComenst.setWidths(new int[] { 550 }); tComenst.setLockedWidth(true); obj.agregaCelda(tComenst, letraNueveBold, Color.lightGray, "Comentarios", new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 2); obj.agregaCelda(tComenst, letraOcho, null, this.degustacion.getComentariosCierre(), new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 2); obj.agregaTabla(mainTable, tComenst, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1); //FIN DE CONTENIDO -------- //Aadimos tabla principal construida al documento doc.add(mainTable); mainTable.flushContent(); } catch (Exception ex) { msgError = "No se ha podido generar la representacin impresa de la Degustacion en formato PDF:<br/>" + ex.toString(); } finally { if (doc.isOpen()) doc.close(); } if (!msgError.equals("")) { throw new Exception(msgError); } return baos; }
From source file:de.dhbw.humbuch.util.PDFHandler.java
/** * Create a standard table with constant table width. * //w w w .j a v a 2 s.c o m * @param columnNumber * set how many columns the table will have * @return table */ protected static PdfPTable createMyStandardTable(int columnNumber) { PdfPTable table = new PdfPTable(columnNumber); table.setLockedWidth(true); table.setTotalWidth(TABLEWIDTH); return table; }
From source file:de.dhbw.humbuch.util.PDFHandler.java
/** * Create a standard table with constant table width. * //from www . ja v a 2 s .c om * @param columnNumber * set how many columns the table will have * @param columnWidths * set the ratio between the columns. If null, all columns will * be equal. * @return table */ protected static PdfPTable createMyStandardTable(int columnNumber, float[] columnWidths) { PdfPTable table = new PdfPTable(columnNumber); table.setLockedWidth(true); table.setTotalWidth(TABLEWIDTH); if (!(columnWidths == null) && (columnWidths.length != 0)) { try { table.setWidths(columnWidths); } catch (DocumentException e) { System.err.println("Could not set columnWidths of standardTable " + e.getStackTrace()); } } return table; }
From source file:de.tr1.cooperator.manager.web.CreateSubscriberListAction.java
License:Open Source License
/** * This method is called by the struts-framework if the submit-button is pressed. * It creates a PDF-File and puts in into the output-stream of the response. *//* w ww . j a va 2 s.c o m*/ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { CreateSubscriberListForm myForm = (CreateSubscriberListForm) form; boolean bSortByName; if (myForm.getSortBy().equals(myForm.SORTBYPN)) bSortByName = false; else bSortByName = true; //create Collection for the results... Event eEvent = EventManager.getInstance().getEventByID(myForm.getEventID()); Collection cSubscriberList = UserManager.getInstance().getUsersByCollection(eEvent.getSubscriberList()); Collection cExamResults = EventResultManager.getInstance().getResults(eEvent.getID()); Iterator cSubscriberListIT = cSubscriberList.iterator(); Collection cSubscriberResultList = new ArrayList(); while (cSubscriberListIT.hasNext()) { User CurUser = (User) cSubscriberListIT.next(); String UserPNR = CurUser.getPersonalNumber(); Iterator cExamResultsIT = cExamResults.iterator(); ExamResult curExamResult = null; String ResultUserPNR = null; while (cExamResultsIT.hasNext()) { curExamResult = (ExamResult) cExamResultsIT.next(); ResultUserPNR = curExamResult.getUserPersonalNumber(); if (UserPNR.equals(ResultUserPNR)) break; } if (UserPNR.equals(ResultUserPNR)) { if (bSortByName) { UserResultSortByName URS = new UserResultSortByName(CurUser, "" + curExamResult.getResult()); cSubscriberResultList.add(URS); } else { UserResultSortByPersonalNumber URS = new UserResultSortByPersonalNumber(CurUser, "" + curExamResult.getResult()); cSubscriberResultList.add(URS); } } else { if (bSortByName) { UserResultSortByName URS = new UserResultSortByName(CurUser, "-"); cSubscriberResultList.add(URS); } else { UserResultSortByPersonalNumber URS = new UserResultSortByPersonalNumber(CurUser, "-"); cSubscriberResultList.add(URS); } } } //sort List Collections.sort((List) cSubscriberResultList); BaseFont bf; //36pt = 0.5inch Document document = new Document(PageSize.A4, 36, 36, 72, 72); try { bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); } catch (Exception e) { Log.addLog("CreateSubscriberListAction: Error creating BaseFont: " + e); //2do: add ErrorMessage and return to inputFormular! return mapping.findForward("GeneralFailure"); } //calculate the number of cols and their width int cols = 0; ArrayList alWidth = new ArrayList(); float boldItalicFactor = 1.2f; if (myForm.getShowNumber()) alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_NUMBER, TABLEHEADER_FONTSIZE))); if (myForm.getShowPersonalNumber()) alWidth.add(new Float( boldItalicFactor * bf.getWidthPoint(TABLEHEADER_PERSONALNUMBER, TABLEHEADER_FONTSIZE))); if (myForm.getShowName()) alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_NAME, TABLEHEADER_FONTSIZE))); if (myForm.getShowEmail()) alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_EMAIL, TABLEHEADER_FONTSIZE))); if (myForm.getShowResult()) alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_RESULT, TABLEHEADER_FONTSIZE))); if (myForm.getAddInfoField()) alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_INFO, TABLEHEADER_FONTSIZE))); if (myForm.getAddSignField()) alWidth.add(new Float(boldItalicFactor * bf.getWidthPoint(TABLEHEADER_SIGN, TABLEHEADER_FONTSIZE))); cols = alWidth.size(); float totalWidth = 0; //calculate the whole length Iterator alIterator = alWidth.iterator(); for (; alIterator.hasNext(); totalWidth += ((Float) alIterator.next()).floatValue()) ; //calculate relativ width for the table float[] width = new float[cols]; alIterator = alWidth.iterator(); int i = 0; while (alIterator.hasNext()) { float pixLength = ((Float) alIterator.next()).floatValue(); //alWidthRelativ.add( new Float( pixLength/totalWidth ) ); width[i] = pixLength / totalWidth; i++; } //needed for the shrink (enlarge?) float shrinkFactor; try { //1st: set correct outputstream PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); //1.5st: set content-stuff response.setContentType("application/pdf"); //2nd: set EventManager for PageEvents to Helper writer.setPageEvent( new CreateSubscriberListActionHelper(myForm.getHeaderLeft(), myForm.getHeaderRight())); //3rd: open document for editing the content document.open(); //4th: add content Phrase pInfoText = new Phrase(myForm.getInfoText(), new Font(bf, 12, Font.BOLD)); document.add(pInfoText); //PdfPTable( cols ) PdfPTable table = new PdfPTable(width); float documentWidth = document.right() - document.left(); if (documentWidth < totalWidth) { table.setTotalWidth(documentWidth); shrinkFactor = documentWidth / totalWidth; } else { table.setTotalWidth(totalWidth); shrinkFactor = 1; } table.setLockedWidth(true); Font headerFont = new Font(bf, TABLEHEADER_FONTSIZE * shrinkFactor, Font.BOLDITALIC); Font cellFont = new Font(bf, TABLECELL_FONTSIZE * shrinkFactor, Font.NORMAL); if (myForm.getShowNumber()) table.addCell(new Phrase(TABLEHEADER_NUMBER, headerFont)); if (myForm.getShowPersonalNumber()) table.addCell(new Phrase(TABLEHEADER_PERSONALNUMBER, headerFont)); if (myForm.getShowName()) table.addCell(new Phrase(TABLEHEADER_NAME, headerFont)); if (myForm.getShowEmail()) table.addCell(new Phrase(TABLEHEADER_EMAIL, headerFont)); if (myForm.getShowResult()) table.addCell(new Phrase(TABLEHEADER_RESULT, headerFont)); if (myForm.getAddInfoField()) table.addCell(new Phrase(TABLEHEADER_INFO, headerFont)); if (myForm.getAddSignField()) table.addCell(new Phrase(TABLEHEADER_SIGN, headerFont)); //fill table Iterator iSRL = cSubscriberResultList.iterator(); int counter = 1; while (iSRL.hasNext()) { UserResult curResult = (UserResult) iSRL.next(); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); if (myForm.getShowNumber()) table.addCell(new Phrase("" + counter++, cellFont)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); if (myForm.getShowPersonalNumber()) table.addCell(new Phrase(curResult.getPersonalNumber(), cellFont)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); if (myForm.getShowName()) table.addCell(new Phrase(curResult.getSurname() + ", " + curResult.getFirstName(), cellFont)); if (myForm.getShowEmail()) table.addCell(new Phrase(curResult.getEmailAddress(), cellFont)); if (myForm.getShowResult()) table.addCell(new Phrase(curResult.getResult(), cellFont)); if (myForm.getAddInfoField()) table.addCell(new Phrase("", cellFont)); if (myForm.getAddSignField()) table.addCell(new Phrase("", cellFont)); } //set how many rows are header... table.setHeaderRows(1); document.add(table); //5th: close document, write the output to the stream... document.close(); } catch (Exception de) { Log.addLog("CreateSubscriberListAction: Error creating PDF: " + de); } //we dont need to return a forward, because we write directly to the outputstream! return null; }
From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPTable.java
License:Open Source License
private PdfPTable createTable(PdfPCell cell) { PdfPTable table = new PdfPTable(1); table.setSpacingBefore(this.spacingBefore()); table.setSpacingAfter(this.spacingAfter()); table.setHorizontalAlignment(this.getHorizontalAlignment()); table.setTotalWidth(cell.getPaddingLeft() + this.getTotalWidth() + cell.getPaddingRight()); table.setLockedWidth(true); table.setSplitLate(false);//from w w w .j a va 2 s . c o m table.addCell(cell); return table; }
From source file:gov.medicaid.binders.LicenseInformationFormBinder.java
License:Apache License
@Override public void renderPDF(EnrollmentType enrollment, Document document, Map<String, Object> model) throws DocumentException { String ns = NAMESPACE;//from w w w .jav a 2 s. c o m if ("Y".equals(PDFHelper.value(model, ns, "bound"))) { // License Info Section PdfPTable licenseInfo = new PdfPTable(new float[] { 3, 10, 10, 10, 10, 10, 10 }); licenseInfo.getDefaultCell().setBorder(0); licenseInfo.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); licenseInfo.setTotalWidth(72 * 7); licenseInfo.setLockedWidth(true); PDFHelper.addCenterCell(licenseInfo, "#"); PDFHelper.addCenterCell(licenseInfo, "Specialty"); PDFHelper.addCenterCell(licenseInfo, "Type of License/Certification"); PDFHelper.addCenterCell(licenseInfo, "License/Certification #"); PDFHelper.addCenterCell(licenseInfo, "Original Issue Date (MM/DD/YYYY)"); PDFHelper.addCenterCell(licenseInfo, "Renewal End Date (MM/DD/YYYY)"); PDFHelper.addCenterCell(licenseInfo, "Issuing State"); licenseInfo.completeRow(); int size = Integer.parseInt(PDFHelper.value(model, ns, "attachmentSize")); for (int i = 0; i < size; i++) { PDFHelper.addCenterCell(licenseInfo, String.valueOf(i + 1)); PDFHelper.addCenterCell(licenseInfo, ""); PDFHelper.addCenterCell(licenseInfo, PDFHelper.value(model, ns, "licenseType", i)); PDFHelper.addCenterCell(licenseInfo, PDFHelper.value(model, ns, "licenseNumber", i)); PDFHelper.addCenterCell(licenseInfo, PDFHelper.value(model, ns, "originalIssueDate", i)); PDFHelper.addCenterCell(licenseInfo, PDFHelper.value(model, ns, "renewalDate", i)); PDFHelper.addCenterCell(licenseInfo, PDFHelper.value(model, ns, "issuingState", i)); } document.add(licenseInfo); } }
From source file:gov.medicaid.binders.MemberInfoFormBinder.java
License:Apache License
@Override public void renderPDF(EnrollmentType enrollment, Document document, Map<String, Object> model) throws DocumentException { String ns = NAMESPACE;// w ww. j a va 2 s . c om if ("Y".equals(PDFHelper.value(model, ns, "bound"))) { // License Info Section PdfPTable membersInfo = new PdfPTable(new float[] { 5, 65 }); membersInfo.getDefaultCell().setBorder(0); membersInfo.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); membersInfo.setTotalWidth(72 * 7); membersInfo.setLockedWidth(true); int size = Integer.parseInt(PDFHelper.value(model, ns, "memberSize")); for (int i = 0; i < size; i++) { PDFHelper.addCenterCell(membersInfo, String.valueOf(i + 1)); PdfPTable memberDetail = new PdfPTable(2); PDFHelper.addLabelValueCell(memberDetail, "NPI", PDFHelper.value(model, ns, "npi", i)); PDFHelper.addLabelValueCell(memberDetail, "Provider Type", PDFHelper.value(model, ns, "providerType", i)); PDFHelper.addLabelValueCell(memberDetail, "Name", PDFHelper.value(model, ns, "name", i)); PDFHelper.addLabelValueCell(memberDetail, "Date Of Birth", PDFHelper.value(model, ns, "dob", i)); PDFHelper.addLabelValueCell(memberDetail, "SSN", PDFHelper.value(model, ns, "ssn", i)); PDFHelper.addLabelValueCell(memberDetail, "Start Date", PDFHelper.value(model, ns, "startDate", i)); membersInfo.addCell(memberDetail); membersInfo.completeRow(); } document.add(membersInfo); } }