List of usage examples for com.lowagie.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.lowagie.text Element ALIGN_LEFT.
Click Source Link
From source file:com.aryjr.nheengatu.pdf.PDFTable.java
License:Open Source License
public static PDFTable createTable(final Tag htmlTable) throws DocumentException { // TODO Do not use <tfoot> tag !!! Inside a <table> only <thead>, // <tbody> and <tr>. // TODO If you are using a <thead>, you can use only <tbody> inside a // <table>. // TODO If you do not use <thead>, you can use only <tr> int headerRowCount = 0; if (htmlTable.getFirstTag("thead") != null || htmlTable.getFirstTag("tbody") != null) { // Before I will remove the <thead> and <tbody> tags headerRowCount = PDFTable.removeTheadTbody(htmlTable); }/*from ww w . j a v a2 s. c o m*/ // Now, I will remove all rowspans from table and convert it to // nestedTables headerRowCount -= PDFTable.removeAllRowspans(htmlTable); // Creating the iText table PDFTable table; final TagsManager tm = TagsManager.getInstance(); int maxCols = 0;// The max number of cells in this table final Iterator rows = htmlTable.tags(); Tag row; while (rows.hasNext()) { row = (Tag) rows.next(); if (maxCols < row.tagsCollection().size()) { maxCols = row.tagsCollection().size(); } } table = new PDFTable(maxCols); table.setHeaderRows(headerRowCount < 0 ? 0 : headerRowCount); tm.checkTag(htmlTable); final CellWidths cws = new CellWidths(); PDFTable.createTableRows(htmlTable, htmlTable, table, cws); tm.back(); String align = htmlTable.getPropertyValue("align"); if (align != null) { align = align.toLowerCase(); if (align.equals("left")) table.setHorizontalAlignment(Element.ALIGN_LEFT); else if (align.equals("right")) table.setHorizontalAlignment(Element.ALIGN_RIGHT); else if (align.equals("center")) table.setHorizontalAlignment(Element.ALIGN_CENTER); } final String width = htmlTable.getPropertyValue("width"); // table.setLockedWidth(true); if (width != null && width.indexOf('%') > 0) { // TODO what is the reference for the % here? See the method // table.setWidthPercentage(float[] , Rectangle). table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1))); } else if (width != null) { table.setTotalWidth(Float.parseFloat(width)); } return table; }
From source file:com.aryjr.nheengatu.util.GraphicsState.java
License:Open Source License
public GraphicsState() { font = FontFactory.getFont(Style.DEFAULT_FONT_FAMILY, Style.DEFAULT_FONT_SIZE, Font.NORMAL, Style.DEFAULT_FONT_COLOR); align = Element.ALIGN_LEFT; valign = Element.ALIGN_MIDDLE; bgcolor = new Color(0, 0, 0); spacingBefore = 8f;/*from w ww . java2s . com*/ spacingAfter = 8f; textIndent = 0f * GraphicsState.CM_UNIT; marginLeft = 0f * GraphicsState.CM_UNIT; listStyleType = null; }
From source file:com.bcpv.webapp.displaytag.decorators.ItextTotalWrapper.java
License:Artistic License
/** * Obtain a cell with the given value.//w ww . j a v a 2 s. co m * @param value Value to display in the cell. * @return A cell with the given value. * @throws com.lowagie.text.BadElementException if an error occurs while generating the cell. */ private Cell getCell(String value) throws BadElementException { Cell cell = new Cell(new Chunk(value, this.font)); cell.setLeading(8); cell.setHorizontalAlignment(Element.ALIGN_LEFT); return cell; }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void startParagraph(ParagraphAligment pParagraphAligment, boolean pBlnParagraphIndent) { mLog.debug("Start startParagraph()"); mParagraph = new Paragraph(22); if (pBlnParagraphIndent) { mParagraph.setFirstLineIndent(PARAGRAPH_FIRST_LINE_INDENT); } else {//from w w w .j a va 2s . co m mParagraph.setFirstLineIndent(0); } switch (pParagraphAligment) { case LEFT: mParagraph.setAlignment(Element.ALIGN_LEFT); break; case CENTER: mParagraph.setAlignment(Element.ALIGN_CENTER); break; case RIGHT: mParagraph.setAlignment(Element.ALIGN_RIGHT); break; case JUSTIFY: mParagraph.setAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } mLog.debug("End startParagraph()"); }
From source file:com.bytecode.customexporter.PDFCustomExporter.java
protected PdfPCell addColumnAlignments(UIComponent component, PdfPCell cell) { if (component instanceof HtmlOutputText) { HtmlOutputText output = (HtmlOutputText) component; if (output.getStyle() != null && output.getStyle().contains("left")) { cell.setHorizontalAlignment(Element.ALIGN_LEFT); }//from w w w .ja v a 2s. c o m if (output.getStyle() != null && output.getStyle().contains("right")) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } if (output.getStyle() != null && output.getStyle().contains("center")) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } } return cell; }
From source file:com.bytecode.customexporter.PDFCustomExporter.java
protected PdfPCell addFacetAlignments(UIComponent component, PdfPCell cell) { if (component instanceof HtmlOutputText) { HtmlOutputText output = (HtmlOutputText) component; if (output.getStyle() != null && output.getStyle().contains("left")) { cell.setHorizontalAlignment(Element.ALIGN_LEFT); } else if (output.getStyle() != null && output.getStyle().contains("right")) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else {/*from w w w. java 2 s.c o m*/ cell.setHorizontalAlignment(Element.ALIGN_CENTER); } } return cell; }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static String parseTable(WikiPDFContext context, Wiki wiki, String line, Document document, Connection db, ArrayList<Integer> wikiListTodo, ArrayList<Integer> wikiListDone, BufferedReader in) throws Exception { if (line == null) { return null; }/*from www. j ava2s . c o m*/ PdfPTable pdfTable = null; int columnCount = 0; int rowCount = 0; // Keep track of the table's custom styles HashMap<Integer, String> cStyle = new HashMap<Integer, String>(); while (line != null && (line.startsWith("|") || line.startsWith("!"))) { // Build a complete line String lineToParse = line; while (!line.endsWith("|")) { line = in.readLine(); if (line == null) { // there is an error in the line to process return null; } if (line.startsWith("!")) { lineToParse += CRLF + line.substring(1); } } line = lineToParse; // Determine if the row can output boolean canOutput = true; ++rowCount; String cellType = null; Scanner sc = null; if (line.startsWith("||") && line.endsWith("||")) { cellType = "th"; sc = new Scanner(line).useDelimiter("[|][|]"); // sc = new Scanner(line.substring(2, line.length() - 2)).useDelimiter("[|][|]"); } else if (line.startsWith("|")) { cellType = "td"; sc = new Scanner(line.substring(1, line.length() - 1)).useDelimiter("\\|(?=[^\\]]*(?:\\[|$))"); } if (sc != null) { if (rowCount == 1) { // Count the columns, get the specified widths too... while (sc.hasNext()) { ++columnCount; sc.next(); } // Reset the scanner now that the columns have been counted if (line.startsWith("||") && line.endsWith("||")) { sc = new Scanner(line).useDelimiter("[|][|]"); } else if (line.startsWith("|")) { sc = new Scanner(line.substring(1, line.length() - 1)) .useDelimiter("\\|(?=[^\\]]*(?:\\[|$))"); } // Start the table pdfTable = new PdfPTable(columnCount); //pdfTable.setWidthPercentage(100); pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT); pdfTable.setSpacingBefore(10); pdfTable.setWidthPercentage(100); pdfTable.setKeepTogether(true); } // Determine the column span int colSpan = 1; // Determine the cell being output int cellCount = 0; while (sc.hasNext()) { String cellData = sc.next(); if (cellData.length() == 0) { ++colSpan; continue; } // Track the cell count being output ++cellCount; if (rowCount == 1) { // Parse and validate the style input LOG.debug("Checking style value: " + cellData); if (cellData.startsWith("{") && cellData.endsWith("}")) { String[] style = cellData.substring(1, cellData.length() - 1).split(":"); String attribute = style[0].trim(); String value = style[1].trim(); // Determine the width of each column and store it if ("width".equals(attribute)) { // Validate the width style if (StringUtils.hasAllowedOnly("0123456789%.", value)) { cStyle.put(cellCount, attribute + ": " + value + ";"); } } else { LOG.debug("Unsupported style: " + cellData); } canOutput = false; } } // Output the header if (canOutput) { PdfPCell cell = new PdfPCell(); cell.setPadding(10); cell.setBorderColor(new Color(100, 100, 100)); if ("th".equals(cellType)) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); } if (colSpan > 1) { cell.setColspan(colSpan); } // Output the data if (" ".equals(cellData) || "".equals(cellData)) { // Put a blank space in blank cells for output consistency cell.addElement(new Chunk(" ")); LOG.debug(" OUTPUTTING A BLANK"); } else { // Output the cell as a complete wiki float cellWidth = (100.0f / columnCount); parseContent(context, wiki, cellData, document, cell, db, wikiListTodo, wikiListDone, cellWidth); LOG.debug(" OUTPUTTING CONTENT"); } pdfTable.addCell(cell); } } } // read another line to see if it's part of the table line = in.readLine(); } if (pdfTable != null) { LOG.debug("document.add(pdfTable)"); document.add(pdfTable); // document.add(Chunk.NEWLINE); } return line; }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
protected static String parseForm(WikiPDFContext context, Connection db, BufferedReader in, String line, Document document, PdfPCell cell) throws Exception { if (line == null) { return line; }/*ww w .j a v a 2 s .c o m*/ CustomForm form = WikiToHTMLUtils.retrieveForm(in, line); LOG.debug("parseForm"); for (CustomFormGroup group : form) { LOG.debug(" group..."); // Start the table PdfPTable pdfTable = new PdfPTable(2); pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT); pdfTable.setSpacingBefore(10); // pdfTable.setWidthPercentage(100); pdfTable.setKeepTogether(true); if (group.getDisplay() && StringUtils.hasText(group.getName())) { // output the 1st row with a colspan of 2 if (StringUtils.hasText(group.getName())) { Paragraph groupParagraph = new Paragraph(group.getName()); PdfPCell groupCell = new PdfPCell(groupParagraph); groupCell.setHorizontalAlignment(Element.ALIGN_CENTER); groupCell.setColspan(2); groupCell.setPadding(20); groupCell.setBorderColor(new Color(100, 100, 100)); groupCell.setBackgroundColor(new Color(200, 200, 200)); groupCell.setNoWrap(true); pdfTable.addCell(groupCell); } } for (CustomFormField field : group) { LOG.debug(" field..."); if (field.hasValue()) { // output the row (2 columns: label, value) Paragraph fieldLabelParagraph = new Paragraph(field.getLabel()); PdfPCell fieldLabelCell = new PdfPCell(fieldLabelParagraph); fieldLabelCell.setPadding(20); fieldLabelCell.setBorderColor(new Color(100, 100, 100)); // fieldLabelCell.setNoWrap(true); pdfTable.addCell(fieldLabelCell); Paragraph fieldValueParagraph = new Paragraph(getFieldValue(context, field)); PdfPCell fieldValueCell = new PdfPCell(fieldValueParagraph); fieldValueCell.setPadding(20); fieldValueCell.setBorderColor(new Color(100, 100, 100)); // fieldValueCell.setNoWrap(true); pdfTable.addCell(fieldValueCell); } } LOG.debug("document.add(pdfTable)"); document.add(pdfTable); } return null; }
From source file:com.crm.webapp.util.PDFCustomExporter.java
License:Apache License
protected void addColumnAlignments(UIComponent component, PdfPCell cell) { if (component instanceof HtmlOutputText) { HtmlOutputText output = (HtmlOutputText) component; if (output.getStyle() != null && output.getStyle().contains("left")) { cell.setHorizontalAlignment(Element.ALIGN_LEFT); }/*from w w w .j a v a 2 s . c om*/ if (output.getStyle() != null && output.getStyle().contains("right")) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } if (output.getStyle() != null && output.getStyle().contains("center")) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } } }
From source file:com.crm.webapp.util.PDFCustomExporter.java
License:Apache License
protected void addColumnAlignments(List<UIComponent> components, PdfPCell cell) { for (UIComponent component : components) { if (component instanceof HtmlOutputText) { HtmlOutputText output = (HtmlOutputText) component; if (output.getStyle() != null && output.getStyle().contains("left")) { cell.setHorizontalAlignment(Element.ALIGN_LEFT); }/* ww w.j a v a 2 s . c o m*/ if (output.getStyle() != null && output.getStyle().contains("right")) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } if (output.getStyle() != null && output.getStyle().contains("center")) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } } } }