List of usage examples for com.itextpdf.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.itextpdf.text Element ALIGN_LEFT.
Click Source Link
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private void getDirectContent(PdfContentByte cb, Rectangle ps, Map it) throws Exception { BaseColor color = getColor(it, "fillColor"); if (color != null) cb.setColorFill(color);/*w ww .j a v a 2 s .c o m*/ float x = MapUtil.getFloat(it, "x", 0f); float y = MapUtil.getFloat(it, "y", 0f); float w = MapUtil.getFloat(it, "w", 0f); float h = MapUtil.getFloat(it, "h", 0f); float xPer = MapUtil.getFloat(it, "xPer", 0f); float yPer = MapUtil.getFloat(it, "yPer", 0f); float wPer = MapUtil.getFloat(it, "wPer", 0f); float hPer = MapUtil.getFloat(it, "hPer", 0f); String pos = MapUtil.getStr(it, "position", "bottom"); switch (pos) { case "top": y += ps.getHeight(); break; case "right": x += ps.getWidth(); break; } float xx = x + ps.getWidth() * xPer / 100f; float yy = y + ps.getWidth() * yPer / 100f; float ww = ps.getWidth() * wPer / 100f + w; float hh = ps.getHeight() * hPer / 100f + h; int font = MapUtil.getInt(it, "fontSize", 8); cb.setFontAndSize(getDefaultFont(), font); cb.beginText(); String cls = MapUtil.getStr(it, "cls", ""); if (cls.equals("image")) { Image img = getImage(it); cb.addImage(img, img.getWidth(), 0, 0, img.getHeight(), xx, yy); } else { String text = LightUtil.macro(MapUtil.getStr(it, "text", ""), '$').toString(); float degree = MapUtil.getFloat(it, "rotateDegree", 0f); boolean kerned = MapUtil.getBool(it, "kerned", false); int align = getAlignment(it, "alignment"); x = xx; y = yy; switch (align) { case Element.ALIGN_CENTER: x = xx + ww / 2; break; case Element.ALIGN_RIGHT: x = xx + ww; break; default: align = Element.ALIGN_LEFT; break; } if (kerned) cb.showTextAlignedKerned(align, text, x, y, degree); else cb.showTextAligned(align, text, x, y, degree); } cb.endText(); }
From source file:com.microware.intrahealth.Createpdf2.java
public static Paragraph mypara(String ab, int flag) { Paragraph preface1 = new Paragraph(ab, subFont); if (flag == 1) preface1.setAlignment(Element.ALIGN_CENTER); if (flag == 2) preface1.setAlignment(Element.ALIGN_LEFT); if (flag == 3) preface1.setAlignment(Element.ALIGN_RIGHT); return preface1; }
From source file:com.microware.intrahealth.Createpdf2.java
private static void createTable(Paragraph preface, String[] Header, ArrayList<HashMap<String, String>> data) throws BadElementException { Context _con = null;/*from w w w. j a v a 2 s . com*/ // PdfPTable table = new PdfPTable(new float[] { 2, 1 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPTable table = new PdfPTable(new float[] { 1, 3, 3, 5, 5, 2, 3, 2, 2, 2 }); table.setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); } // table.addCell("Value"); // table.addCell("Location"); table.setHeaderRows(1); // PdfPCell c1 = new PdfPCell(new Phrase("Text",smallBold)); // c1.getBorder(); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // table.addCell(c1); // // c1 = new PdfPCell(new Phrase("Value",smallBold)); // c1.getBorder(); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // table.addCell(c1); // // table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); // // Font f = FontFactory.getFont(getFilesDir() + "/" + HINDI_FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // PdfPCell eCell = new PdfPCell(new Phrase(entry, f)); for (int i = 0; i < data.size(); i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(data.get(i).get("ASHAName"), subFont)); table.addCell(String.valueOf((i + 1))); table.addCell(data.get(i).get("ASHAName")); table.addCell(data.get(i).get("VillageName")); table.addCell(data.get(i).get("PWName")); table.addCell(data.get(i).get("MotherMCTSID")); table.addCell(data.get(i).get("HusbandName")); table.addCell(Validate.changeDateFormat(data.get(i).get("CheckupVisitDate"))); table.addCell(data.get(i).get("DangerSign")); table.addCell(data.get(i).get("CheckupPlace")); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); // cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); // cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER); } // table.addCell("Colour"); // table.addCell("Hazen Unit"); // table.addCell("1.2"); // table.addCell("Turbidity"); // table.addCell("NTU"); // table.addCell("2.3"); preface.add(table); }
From source file:com.microware.intrahealth.Createpdf2.java
private static void createTable1(Paragraph preface, String Text, String Value) throws BadElementException { Context _con = null;/*w w w . ja v a 2 s. c om*/ PdfPTable table = new PdfPTable(new float[] { 1, 3 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < 2; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase()); table.addCell(c1); } PdfPCell[] cells = table.getRow(0).getCells(); // for (int j=0;j<cells.length;j++){ cells[0].setHorizontalAlignment(Element.ALIGN_LEFT); // } dataprovider = new DataProvider(_con); if (Text.length() > 0 && Value.length() > 0) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(Value); } else { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(""); } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable1(Paragraph preface, String[] Header, String[] Text, String[] Value) throws BadElementException { Context _con = null;/*from w ww .ja va 2 s. c o m*/ PdfPTable table = new PdfPTable(new float[] { 2, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(Value[i]); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); } } else { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable2(Paragraph preface, String[] Header, String[] Text, String[] Source, String[] Value) throws BadElementException { Context _con = null;//w w w . j av a 2s . c o m PdfPTable table = new PdfPTable(new float[] { 2, 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(Source[i]); table.addCell(Value[i]); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER); } } else { for (int i = 0; i < Value.length; i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text[i], subFont)); table.addCell(phrase); table.addCell(""); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable3(Paragraph preface, String[] Header, String[] Text, String[] Value, String[] Value1, String[] Value2) throws BadElementException { Context _con = null;/*ww w . j a v a 2s .c o m*/ PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); if (Text != null && Text.length > 0) { if (Text.length == Value.length) { for (int i = 0; i < Value.length; i++) { table.addCell(Text[i]); table.addCell(Value[i]); table.addCell(Value1[i]); table.addCell(Value2[i]); } } else { for (int i = 0; i < Value.length; i++) { table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); } } } else { table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable4(Paragraph preface, String[] Header, String Text, String Value) throws BadElementException { Context _con = null;/* www. j a v a2 s . co m*/ PdfPTable table = new PdfPTable(new float[] { 1, 1 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); if (Text.length() > 0 && Value.length() > 0) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(Value); PdfPCell[] cells1 = table.getRow(1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); } else { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(""); PdfPCell[] cells1 = table.getRow(1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); } preface.add(table); }
From source file:com.microware.intrahealth.Createpdfall.java
private static void createTable7(Paragraph preface, String Text, String Value) throws BadElementException { Context _con = null;/* w ww . j ava 2 s . co m*/ PdfPTable table = new PdfPTable(new float[] { 1, 2 }); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < 2; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase()); table.addCell(c1); } PdfPCell[] cells = table.getRow(0).getCells(); // for (int j=0;j<cells.length;j++){ cells[0].setHorizontalAlignment(Element.ALIGN_LEFT); // } dataprovider = new DataProvider(_con); if (Text.length() > 0 && Value.length() > 0) { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(Value); } else { Phrase phrase = new Phrase(); phrase.add(new Chunk(Text, subFont)); table.addCell(phrase); table.addCell(""); } preface.add(table); }
From source file:com.miraflorescarwash.controller.PdfController.java
private void crearPdfLavadasPendientes(Document doc, List<Lavada> lavadas) { Paragraph parrafo;/*from w ww . ja va2 s .c o m*/ PdfPTable tabla; String txt; PdfPCell cell; Phrase frase; String fuente; int i; JFreeChart chart; int w, h; int pos; pos = 0; w = h = 500; fuente = "arial"; if (lavadas.isEmpty()) { return; } try { // // Se abre el documento. doc.open(); txt = "Miraflores Car Wash"; parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK)); parrafo.setAlignment(Element.ALIGN_LEFT); doc.add(parrafo); txt = "Lavadas Pendientes"; parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK)); parrafo.setAlignment(Element.ALIGN_CENTER); doc.add(parrafo); LineSeparator ls = new LineSeparator(); doc.add(new Chunk(ls)); tabla = new PdfPTable(3); frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE)); cell = new PdfPCell(frase); cell.setBackgroundColor(BaseColor.RED); tabla.addCell(cell); frase = new Phrase("Fecha", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE)); cell = new PdfPCell(frase); cell.setBackgroundColor(BaseColor.RED); tabla.addCell(cell); frase = new Phrase("Placa de Carro", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE)); cell = new PdfPCell(frase); cell.setBackgroundColor(BaseColor.RED); tabla.addCell(cell); frase = new Phrase("Modelo de Carro", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE)); cell = new PdfPCell(frase); cell.setBackgroundColor(BaseColor.RED); tabla.addCell(cell); frase = new Phrase("Cliente", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE)); cell = new PdfPCell(frase); cell.setBackgroundColor(BaseColor.RED); tabla.addCell(cell); i = 1; for (Lavada lavada : lavadas) { if (i % 2 == 0) { cell = new PdfPCell(); cell.setBackgroundColor(new BaseColor(244, 119, 119)); frase = new Phrase(lavada.getId() + ""); cell.setPhrase(frase); tabla.addCell(cell); frase = new Phrase(lavada.getFechaLavado() + ""); cell.setPhrase(frase); tabla.addCell(cell); frase = new Phrase(lavada.getCarro().getPlaca()); cell.setPhrase(frase); tabla.addCell(cell); frase = new Phrase(lavada.getCarro().getModelo().getNombre()); cell.setPhrase(frase); tabla.addCell(cell); frase = new Phrase(lavada.getCarro().getCliente().getApellidos() + ", " + lavada.getCarro().getCliente().getNombres()); cell.setPhrase(frase); tabla.addCell(cell); } else { tabla.addCell(lavada.getId() + ""); tabla.addCell(lavada.getFechaLavado() + ""); tabla.addCell(lavada.getCarro().getPlaca()); tabla.addCell(lavada.getCarro().getModelo().getNombre()); tabla.addCell(lavada.getCarro().getCliente().getApellidos() + ", " + lavada.getCarro().getCliente().getNombres()); } i++; } doc.add(tabla); doc.close(); } catch (DocumentException ex) { } }