List of usage examples for com.lowagie.text.pdf PdfPTable getDefaultCell
public PdfPCell getDefaultCell()
PdfPCell
that will be used as reference for all the addCell
methods except addCell(PdfPCell)
. From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosDerecha(Paragraph datosDerecha) throws Exception { ciudad = Cotizacion.PanelCotizacion.labelCiudad.getText(); Connection conexion = null;//from w ww . j av a2 s .co m try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); // System.out.println("nombre++++----> "+nombreCliente); ResultSet rs = stm.executeQuery("SELECT * FROM todolonas.ajustes;"); while (rs.next()) { telefonoNegocio = rs.getString("telefonoNegocio"); numeroCelular = rs.getString("numeroCelular"); correoNegocio = rs.getString("correoNegocio"); domicilioNegocio = rs.getString("domicilioNegocio"); RFC = rs.getString("RFC"); leyendaCotizacion = rs.getString("leyendaCotizacion"); colonia = rs.getString("colonia"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } PdfPTable table = new PdfPTable(2); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table.addCell(""); table.addCell(telefonoNegocio); table.addCell(""); table.addCell(numeroCelular); table.addCell(""); table.addCell(correoNegocio); table.addCell(""); table.addCell(domicilioNegocio); table.addCell(""); table.addCell(colonia); table.addCell(""); table.addCell(RFC); table.addCell(""); table.addCell(ciudad); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_RIGHT); datosDerecha.add(table); }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosDerecha2(Paragraph datosDerecha2) { fecha = PanelCotizacion.labelObtenerFecha.getText(); ubicacion = PanelCotizacion.cajaAsunto.getText(); asunto = PanelCotizacion.cajaUbicacion.getText(); PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Fecha"); table2.addCell(fecha);//from ww w . j av a 2 s . co m table2.addCell("Ubicacin"); table2.addCell(ubicacion); table2.addCell("Asunto"); table2.addCell(asunto); table2.setWidthPercentage(50); table2.setHorizontalAlignment(350); table2.setHorizontalAlignment(Element.ALIGN_RIGHT); datosDerecha2.add(table2); }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosEspecificaciones(Paragraph datosNormal) throws BadElementException { Connection conexion = null;/*w w w . j av a 2 s . c o m*/ try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); ResultSet rs = stm.executeQuery("select max(numero) as numero from todolonas.cotizacion;"); while (rs.next()) { idCotiza = rs.getInt("numero"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); ResultSet rs = stm.executeQuery( "SELECT especificacionTrabajo FROM todolonas.cotizacion where numero = '" + idCotiza + "';"); while (rs.next()) { especificacionTrabajo = rs.getString("especificacionTrabajo"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } if (especificacionTrabajo.equals("NA")) { System.out.println("no hay especificacion trabajo"); } else { PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Especificacin Trabajo"); table2.addCell(especificacionTrabajo); table2.setWidthPercentage(70); table2.setHorizontalAlignment(Element.ALIGN_LEFT); agregarLineasEnBlanco(datosNormal, 1); datosNormal.add(table2); } try { Class.forName("org.gjt.mm.mysql.Driver"); conexion = (Connection) DriverManager.getConnection(url, login, password); stm = (Statement) conexion.createStatement(); // System.out.println("nombre++++----> "+nombreCliente); ResultSet rs = stm.executeQuery( "SELECT especificacionDiseno FROM todolonas.cotizacion where numero = '" + idCotiza + "';"); while (rs.next()) { especificacionDiseno = rs.getString("especificacionDiseno"); } conexion.close(); } catch (Exception e) { System.out.println("error: " + e); } if (especificacionDiseno.equals("NA")) { System.out.println("no hay especificacion trabajo"); } else { PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Especificacin Diseo"); table2.addCell(especificacionDiseno); table2.setWidthPercentage(70); table2.setHorizontalAlignment(Element.ALIGN_LEFT); agregarLineasEnBlanco(datosNormal, 1); datosNormal.add(table2); } }
From source file:Cotizacion.ExportarPDF.java
private static void acomodarDatosPreciosTotales(Paragraph datosDerecha2) throws BadElementException { subtotal = PanelCotizacion.cajaSubtotal.getText(); iva = PanelCotizacion.cajaIVA.getText(); descuento = PanelCotizacion.cajaDescuento.getText(); total = PanelCotizacion.cajaTotal.getText(); PdfPTable table2 = new PdfPTable(2); table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); table2.addCell("Subtotal"); table2.addCell("$ " + subtotal); table2.addCell("IVA"); table2.addCell(iva);/*from w w w.ja v a 2 s .c o m*/ table2.addCell("Descuento"); table2.addCell(descuento); table2.addCell("Total"); table2.addCell("$ " + total); table2.setWidthPercentage(30); table2.setHorizontalAlignment(350); table2.setHorizontalAlignment(Element.ALIGN_RIGHT); agregarLineasEnBlanco(datosDerecha2, 1); datosDerecha2.add(table2); }
From source file:CPS.Core.TODOLists.PDFExporter.java
License:Open Source License
private Document prepareDocument(String filename, final String title, final String author, final String creator, final Rectangle pageSize) { System.out.println("DEBUG(PDFExporter): Creating document: " + filename); Document d = new Document(); d.setPageSize(pageSize);// w ww . java 2 s . co m // TODO alter page orientation? maybe useful for seed order worksheet d.addTitle(title); d.addAuthor(author); // d.addSubject( ); // d.addKeywords( ); d.addCreator(creator); // left, right, top, bottom - scale in points (~72 points/inch) d.setMargins(35, 35, 35, 44); try { PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream(filename)); // add header and footer writer.setPageEvent(new PdfPageEventHelper() { public void onEndPage(PdfWriter writer, Document document) { try { Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(3); head.getDefaultCell().setBorderWidth(0); head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); head.addCell(new Phrase(author, fontHeadFootItal)); head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); head.addCell(new Phrase(title, fontHeadFootReg)); head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); head.addCell(""); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); PdfPTable foot = new PdfPTable(3); foot.getDefaultCell().setBorderWidth(0); foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); foot.addCell(new Phrase(creator, fontHeadFootItal)); foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); foot.addCell(""); foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); foot.addCell(new Phrase("Page " + document.getPageNumber(), fontHeadFootReg)); foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } catch (Exception e) { throw new ExceptionConverter(e); } } }); } catch (Exception e) { e.printStackTrace(); } return d; }
From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private PdfPTable writePdfMetaTable(List<SudokuData> sudokus) throws DocumentException { // Tabelle fr Formatierung von 2 Sudokus nebeneinander PdfPTable metaTable = new PdfPTable(2); metaTable.getDefaultCell().setBorder(0); metaTable.getDefaultCell().setPadding(5); metaTable.setWidthPercentage(100);/*from ww w .java 2 s .c o m*/ metaTable.setHorizontalAlignment(Element.ALIGN_CENTER); int cells = 0; for (SudokuData sudoku : sudokus) { metaTable.addCell(writePdfTable(sudoku)); cells++; } final int rest = cells % 2; for (int i = 0; i < rest; i++) { metaTable.addCell(""); } metaTable.setComplete(true); return metaTable; }
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. *//*from ww w . j a v a 2s . com*/ 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:domain.reports.menu.PDFReportMenu.java
License:LGPL
/** * Return a report section formatted as a table * @param data//ww w .j a v a2 s. c o m * @return */ PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable { //cols PdfPTable datatable = new PdfPTable(2); //header datatable.getDefaultCell().setPadding(1); int headerwidths[] = { 50, 50 }; // percentage datatable.setWidths(headerwidths); datatable.setWidthPercentage(70); // percentage datatable.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell c = null; String v = ""; //encabezados de columnas c = new PdfPCell(new Phrase("ITEMS DEL MEN", tblHeaderFont)); c.setGrayFill(0.95f); c.setColspan(2); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Item del men", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Servicio", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); while (detail.next()) { v = detail.getString("description"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(c); v = detail.getString("path"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(c); } datatable.setSpacingBefore(20); return datatable; }
From source file:domain.reports.role.PDFReportRole.java
License:LGPL
/** * Return a report section formatted as a table * @param data//from w w w . j a v a2 s . co m * @return */ PdfPTable getGroupDetail(Recordset master, Recordset detail) throws Throwable { //cols PdfPTable datatable = new PdfPTable(4); //header datatable.getDefaultCell().setPadding(1); int headerwidths[] = { 20, 20, 20, 20 }; // percentage datatable.setWidths(headerwidths); datatable.setWidthPercentage(100); // percentage datatable.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell c = null; String v = ""; //encabezados de columnas c = new PdfPCell(new Phrase("USUARIOS DEL ROL", tblHeaderFont)); c.setGrayFill(0.95f); c.setColspan(4); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Login de Usuario", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Apellido", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Nombre", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); c = new PdfPCell(new Phrase("Email", tblHeaderFont)); c.setGrayFill(0.95f); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); while (detail.next()) { v = detail.getString("userlogin"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("lname"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("fname"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); v = detail.getString("email"); c = new PdfPCell(new Phrase(v, tblBodyFont)); c.setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(c); } datatable.setSpacingBefore(20); return datatable; }
From source file:fr.opensagres.xdocreport.itext.extension.TableWithAlignment.java
License:Open Source License
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {//from w ww . j a va2 s . com PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TableWithAlignment.pdf")); document.open(); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(true); table.setWidths(new float[] { 5, 10 }); table.setWidthPercentage(10); PdfPCell cell1 = new PdfPCell(); cell1.addElement(new Chunk("cell1")); table.addCell(cell1); PdfPCell cell2 = new PdfPCell(); cell2.addElement(new Chunk("cell2")); table.addCell(cell2); table.setSpacingBefore(-100); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }