List of usage examples for com.itextpdf.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.itextpdf.text Element ALIGN_CENTER.
Click Source Link
From source file:drugsupplychain.neu.css.gui.common.distributor.GenerateBillPDF.java
/** * create table//ww w . j a va 2 s. co m * @param subCatPart * @throws BadElementException */ private static int createTable(Section subCatPart, Order order) throws BadElementException { PdfPTable table = new PdfPTable(3); PdfPCell c1 = new PdfPCell(new Phrase("Order Item ID")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Quantity")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Value")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); int totalPrice = 0; for (OrderItem orderItem : order.getOrderItemList()) { table.addCell(orderItem.getProduct().getBarcode()); table.addCell(String.valueOf(orderItem.getQuantity())); table.addCell(String.valueOf(orderItem.getQuantity() * orderItem.getProduct().getPrice())); totalPrice = totalPrice + (orderItem.getQuantity() * orderItem.getProduct().getPrice()); } subCatPart.add(table); return totalPrice; }
From source file:edu.bedelias.utils.ReportsService.java
private static void addStudentGrid(java.util.List<Student> students, Document document) throws DocumentException { Paragraph results = new Paragraph(); // Add a table PdfPTable table = new PdfPTable(3); PdfPCell c1 = new PdfPCell(new Phrase("CI Estudiante")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from w ww.java 2 s .c o m c1 = new PdfPCell(new Phrase("Nombre Completo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Resultado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (Student s : students) { table.addCell(s.getCedula()); table.addCell(s.getName()); table.addCell(""); } results.add(table); // Now add all this to the document document.add(results); }
From source file:edu.clemson.lph.pdfgen.PDFGen.java
License:Open Source License
private void printDoc() { if (sSourceFile == null || osDest == null) { logger.error("Cannot print nothing"); return;//ww w . j a v a 2 s. c o m } boolean bBold = false; boolean bCenter = false; boolean bItalic = false; boolean bSmallItalic = false; boolean bUnderline = false; try { Document doc = new Document(); float fCorr = doc.getPageSize().getWidth() / 8.5f; doc.setMargins(1.0f * fCorr, 1.0f * fCorr, 1.0f * fCorr, 1.0f * fCorr); PdfWriter.getInstance(doc, osDest); doc.open(); BufferedReader br = new BufferedReader(new FileReader(sSourceFile)); String sLine = br.readLine(); while (sLine != null) { bBold = false; bCenter = false; if (sLine.startsWith(".")) { String sRest = sLine.substring(1); String sCodes = sRest.substring(0, sRest.indexOf('.')); sLine = sRest.substring(sRest.indexOf('.') + 1); if ("image".equals(sCodes)) { String sFileName = sLine; com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName); image.setAlignment(Element.ALIGN_CENTER); doc.add(image); sLine = br.readLine(); continue; } else if ("himage".equals(sCodes)) { String sFileName = sLine; com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName); image.scaleToFit(500, 40); image.setAlignment(Element.ALIGN_CENTER); doc.add(image); Paragraph p = new Paragraph(" "); doc.add(p); sLine = br.readLine(); continue; } else if ("fimage".equals(sCodes)) { int iBlanks = 9; // How do I figure out how many to get to end? for (int i = 0; i < iBlanks; i++) { Paragraph p = new Paragraph(" "); doc.add(p); } String sFileName = sLine; com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName); image.scaleToFit(500, 40); image.setAlignment(Element.ALIGN_CENTER); doc.add(image); sLine = br.readLine(); continue; } else if ("list".equals(sCodes)) { String sFullLine = doSub(sLine); StringTokenizer tok = new StringTokenizer(sFullLine, "\n"); List list = new List(List.UNORDERED); while (tok.hasMoreTokens()) { String sNextLine = tok.nextToken(); ListItem listItem = new ListItem(sNextLine, fNormal); list.add(listItem); } doc.add(list); sLine = br.readLine(); continue; } if (sCodes.contains("b")) bBold = true; if (sCodes.contains("c")) bCenter = true; if (sCodes.contains("i")) bItalic = true; if (sCodes.contains("si")) bSmallItalic = true; if (sCodes.contains("u")) bUnderline = true; } if (sLine.trim().length() == 0) sLine = " "; String sFullLine = doSub(sLine); Paragraph p = new Paragraph(); if (bBold) p.setFont(fBold); else if (bSmallItalic) p.setFont(fSmallItalic); else if (bItalic) p.setFont(fItalic); else if (bUnderline) p.setFont(fUnderline); else p.setFont(fNormal); if (bCenter) { p.setAlignment(Element.ALIGN_CENTER); } else { p.setAlignment(Element.ALIGN_LEFT); } p.add(sFullLine); doc.add(p); sLine = br.readLine(); } br.close(); doc.close(); } catch (FileNotFoundException e) { logger.error("Could not find source file " + sSourceFile + " or destination", e); } catch (IOException e) { logger.error("Could not read file " + sSourceFile, e); } catch (DocumentException e) { logger.error("Error creating iText Document", e); } }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
private void createImage(Document document, PdfWriter writer, Font featureHeaderStyle) throws BadElementException, MalformedURLException, IOException, DocumentException { Image imageSprite = Image.getInstance(new URL( "http://lh3.ggpht.com/_4msVPAgKJv8/SCRYD-pPVKI/AAAAAAAAAYU/zUN963EPoZc/s1024/102_0609.JPG")); imageSprite.setAbsolutePosition(400, 500); imageSprite.scaleAbsolute(171.0f, 250.0f); float imageSpriteY = document.getPageSize().getHeight() * 0.60f; float imageSpriteX = document.getPageSize().getWidth() * 0.65f; imageSprite.setAlignment(Image.UNDERLYING); document.add(imageSprite);/*from ww w . j av a2s.c om*/ PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); Chunk imageHeader = new Chunk("Images", featureHeaderStyle); ct.addText(imageHeader); ct.setAlignment(Element.ALIGN_LEFT); ct.setSimpleColumn(imageSpriteX, imageSpriteY - imageSprite.getScaledHeight(), imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY + imageSprite.getScaledHeight() + 20); ct.go(); ct = new ColumnText(cb); Chunk imageFooter = new Chunk("Footer to be set for a figure. Similar to 'image cpation'.", FontFactory.getFont(FontFactory.TIMES_ROMAN, 8)); ct.addText(imageFooter); ct.setAlignment(Element.ALIGN_CENTER); ct.setSimpleColumn(imageSpriteX, imageSpriteY - 150, imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY); ct.go(); }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
private void setTableFooterStyle(BaseColor footerBackgroundColor, PdfPCell cell) { cell.setBorderWidth(0.0f);/*from w w w .java 2 s. com*/ cell.setBackgroundColor(footerBackgroundColor); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingTop(5f); cell.setPaddingRight(10f); cell.setPaddingBottom(5f); cell.setPaddingLeft(10f); }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
private void setTableBodyStyle(BaseColor bodyBackgroundColor, PdfPCell cell) { cell.setBorderWidth(0.0f);/*from www . j av a2 s .c o m*/ cell.setBackgroundColor(bodyBackgroundColor); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingTop(5f); cell.setPaddingRight(10f); cell.setPaddingBottom(5f); cell.setPaddingLeft(10f); }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
private void setTableHeaderStyle(BaseColor headerBackgroundColor, PdfPCell cell) { cell.setBorderWidth(0.0f);//w w w . ja v a 2 s . c om cell.setBackgroundColor(headerBackgroundColor); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingTop(5f); cell.setPaddingRight(10f); cell.setPaddingBottom(5f); cell.setPaddingLeft(10f); }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
private void setTableCaptionStyle(BaseColor summaryBackgroundColor, PdfPCell cell) { cell.setBorderWidth(0.0f);// w w w . j av a 2 s .c om cell.setBackgroundColor(summaryBackgroundColor); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingTop(5.0f); cell.setPaddingRight(10.0f); cell.setPaddingBottom(5.0f); cell.setPaddingLeft(10.0f); cell.setColspan(2); }
From source file:edu.eci.pdsw.aeci.managedbeans.GenerarPDFbean.java
@PostConstruct public void init() { try {/*from ww w . j a va2 s . c o m*/ //---------------------------------- nombre = login.getPersonaLog().getFirstName() + " " + login.getPersonaLog().getLastName(); Carrera = login.getPersonaLog().getProgram().getName(); periodo = login.getPersonaLog().getPeriod(); String pe = login.getPersonaLog().getYearGraduate() + " - " + periodo; Cedula = login.getPersonaLog().getId(); Document doc = new Document(); Paragraph parrafo, parrafo2, parrafo3, parrafo4; Image imagenLogo = Image.getInstance("Logo.jpeg"); Image imagenFirma = Image.getInstance("firmaDigital.jpeg"); OutputStream out = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(doc, out); doc.open(); imagenLogo.setAlignment(Element.ALIGN_CENTER); doc.add(imagenLogo); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); parrafo = new Paragraph("CERTIFICADO DE AFILIACIN AECI"); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); parrafo2 = new Paragraph( "La Asociacin de Egresados de la Escuela Colombiana de Ingeniera Julio Garavito AECI, con " + "Nit. 830.031.137- 4, certifica que el Ingeniero(a) egresado de la carrera " + Carrera + " Graduado en el periodo " + pe + "," + " " + nombre + ", identificado con la cdula de Ciudadana N" + Cedula + "," + " est afiliado a esta Asociacin y se encuentra al da con su aporte, " + " el cual fue realizado a travs de la consignacin " + Consignacion + " y" + " la factura de venta N " + factura + " del dia " + fechaActual); parrafo2.setAlignment(Element.ALIGN_JUSTIFIED); doc.add(parrafo2); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); /** add **/ parrafo = new Paragraph("Coordialmente"); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); imagenFirma.setAlignment(Element.ALIGN_CENTER); doc.add(imagenFirma); parrafo = new Paragraph("JUAN CARLOS ROMERO ORDEZ"); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); parrafo = new Paragraph("Director"); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); parrafo = new Paragraph("Asociacion de Egresados Escuela Colombiana de Ingeniera Julio Garavito"); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); parrafo = new Paragraph( "AK 45 no 205-59 * Bloque A -piso 2 * Telfonos 6683600 ext 323-Mvil 3124570612 *"); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); parrafo = new Paragraph( "Correo electronico aeci@escuelaing.edu.co * Facebook Twitter AECI/escuelaing www.aeci.org.co"); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); parrafo = new Paragraph("Bogot-Colombia"); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); doc.close(); out.close(); InputStream in = new ByteArrayInputStream(((ByteArrayOutputStream) out).toByteArray()); streamedContent = new DefaultStreamedContent(in, "application/pdf"); //------- Map<String, Object> session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap(); byte[] b = (byte[]) session.get("reportBytes"); if (b != null) { streamedContent = new DefaultStreamedContent(new ByteArrayInputStream(b), "application/pdf"); } } catch (Exception e) { System.out.println(Carrera + "mierdaadw"); } }
From source file:edu.esprit.pi.gui.internalframes.PDFwithItextInternalFrame.java
public void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); PdfPCell c1 = new PdfPCell(new Phrase("Client")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/*from w w w . j a va2s .c om*/ c1 = new PdfPCell(new Phrase("Article")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Quantit")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); // Rcupration de la liste des articles. java.util.List<Article> listArticles = new ArticleDAO().findAll(); // remplissare des cellules de la liste for (Article article : listArticles) { table.addCell("" + article.getClient().getNom()); table.addCell("" + article.getStock().getLibelle()); table.addCell("" + article.getQuantite()); } subCatPart.add(table); }