Example usage for com.lowagie.text.pdf PdfPCell setBorder

List of usage examples for com.lowagie.text.pdf PdfPCell setBorder

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setBorder.

Prototype

public void setBorder(int border) 

Source Link

Document

Enables/Disables the border on the specified sides.

Usage

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

private Element buildQrCodeSection() throws IOException, DocumentException {
    // Load images
    Image qrApkImage = PngImage/*from w ww  .  j a  v  a 2 s  . c  o  m*/
            .getImage(PdfExporter.class.getResourceAsStream("/export/qr/songbook_apk_qr.png"));
    Image qrPdfImage = PngImage
            .getImage(PdfExporter.class.getResourceAsStream("/export/qr/songbook_pdf_qr.png"));

    PdfPCell cell = new PdfPCell((Phrase) null);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100);
    table.setWidths(new float[] { 1, 2, 1 });

    cell.setImage(qrApkImage);
    table.addCell(cell);
    cell.setImage(null);

    table.addCell(cell);

    cell.setImage(qrPdfImage);
    table.addCell(cell);
    cell.setImage(null);

    cell.setPhrase(new Phrase("APP"));
    table.addCell(cell);
    cell.setPhrase(null);

    table.addCell(cell);

    cell.setPhrase(new Phrase("PDF"));
    table.addCell(cell);
    cell.setPhrase(null);

    return table;
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Set the logo of Humboldt on the left corner and the current date on the
 * right corner// www .ja v  a2 s  .  c o m
 * 
 * @param document
 *            reference of the pdfDocument object
 */
protected void addHeading(Document document) {
    Paragraph paragraph = new Paragraph();
    PdfPTable table = createMyStandardTable(2);

    table.setTotalWidth(TABLEWIDTH);
    PdfPCell cell;

    Image img = new ResourceLoader("pdf/humboldt_logo.png").getImage();
    img.setAlignment(Element.ALIGN_BOTTOM);
    img.scaleToFit(205f, 65f);
    cell = new PdfPCell(img);

    cell.setBorder(0);
    table.addCell(cell);

    String date = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMAN).format(Calendar.getInstance().getTime());

    cell = new PdfPCell(new Phrase(date));
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);

    paragraph.add(table);
    addEmptyLine(paragraph, 1);

    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Adds a signature field with a date field to the document. Should be the
 * last part that is added to the document.
 * //from  www.j  a v  a2  s  .c om
 * @param document
 *            represents the PDF before it is saved
 * @param role
 *            word for the kind of person that shall sign the paper
 */
protected void addSignatureField(Document document, String role) {
    Paragraph paragraph = new Paragraph();

    //this table contains the signatureTable and the dataTable.
    // this purpose makes it easier to format
    PdfPTable table = createMyStandardTable(2);

    //the first column is double times greater than the second column
    try {
        table.setWidths(new float[] { 10f, 20f });
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    //create and fill date table
    PdfPTable dateTable = new PdfPTable(1);

    PdfPCell cell = new PdfPCell(new Phrase(""));
    //just the bottom border will be displayed (line for date)
    cell.setBorderWidthTop(0);
    cell.setBorderWidthLeft(0);
    cell.setBorderWidthRight(0);

    dateTable.addCell(cell);

    cell = new PdfPCell(new Phrase("Datum"));
    cell.setBorder(0);

    dateTable.addCell(cell);

    //put date table into the 'parent' table
    cell = new PdfPCell(dateTable);
    cell.setBorder(0);
    table.addCell(cell);

    //create and fill signature table
    PdfPTable signatureTable = new PdfPTable(1);
    cell = new PdfPCell(new Phrase(""));
    //just the bottom border will be displayed (line for signature)
    cell.setBorderWidthTop(0);
    cell.setBorderWidthLeft(0);
    cell.setBorderWidthRight(0);

    signatureTable.addCell(cell);

    cell = new PdfPCell(new Phrase("Unterschrift " + role));
    cell.setBorder(0);

    signatureTable.addCell(cell);

    //put signature table into the 'parent' table
    cell = new PdfPCell(signatureTable);
    cell.setBorder(0);
    table.addCell(cell);

    paragraph.add(table);
    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Use the configuration information to fill the table cells
 * @param tableBuilder Table configuration
 *//*  w  w w .  jav  a  2  s.  com*/
private static void fillTableWithContent(TableBuilder tableBuilder) {
    PdfPCell cell = null;
    for (int i = 0; i < tableBuilder.contentArray.length; i++) {
        if (tableBuilder.contentArray[i] == null || tableBuilder.contentArray[i].equals("null")) {
            tableBuilder.contentArray[i] = "";
        }
        if (tableBuilder.font != null) {
            cell = new PdfPCell(new Phrase(tableBuilder.contentArray[i], tableBuilder.font));
        } else {
            cell = new PdfPCell(new Phrase(tableBuilder.contentArray[i]));
        }
        if (tableBuilder.isAlignedCentrally) {
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        }
        if (!tableBuilder.withBorder) {
            cell.setBorder(0);
        }
        if (tableBuilder.padding != 0f) {
            cell.setPadding(tableBuilder.padding);
        }
        if (tableBuilder.leading != 0f) {
            cell.setLeading(tableBuilder.leading, tableBuilder.leading);
        }
        tableBuilder.table.addCell(cell);
    }
}

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private PdfPTable writePdfTable(SudokuData sudokuData) {
    PdfPTable einzelnesSudoku = new PdfPTable(1);
    PdfPTable ueberschrift = new PdfPTable(2);
    PdfPCell linkeZelle = new PdfPCell(new Phrase("ID: " + sudokuData.getId()));
    linkeZelle.getPhrase().getFont().setSize(9f);
    linkeZelle.setBorder(Integer.parseInt(getPdfStyle().getProperty("border.none")));
    linkeZelle.setHorizontalAlignment(Element.ALIGN_LEFT);
    ueberschrift.addCell(linkeZelle);/*from   w ww .  j  ava 2 s .  co  m*/
    PdfPCell rechteZelle = new PdfPCell(
            new Phrase(Level.valueOf(sudokuData.getLevel()).getName() + " (" + sudokuData.getFixed() + ")"));
    rechteZelle.getPhrase().getFont().setSize(9f);
    rechteZelle.setBorder(0);
    rechteZelle.setHorizontalAlignment(Element.ALIGN_RIGHT);
    ueberschrift.addCell(rechteZelle);
    PdfPCell obereZelle = new PdfPCell(ueberschrift);
    obereZelle.setBorder(0);
    einzelnesSudoku.addCell(obereZelle);
    PdfCellHandler pdfCellHandler = new PdfCellHandler(SudokuSize.getByUnitSize(sudokuData.getSize()),
            getPdfStyle());
    pdfCellHandler.initialize();
    HandlerUtil.forEachCell(SudokuFactory.INSTANCE.buildSudoku(sudokuData.getSudokuAsString()), pdfCellHandler);
    PdfPCell untereZelle = new PdfPCell(pdfCellHandler.getTable());
    untereZelle.setBorder(0);
    einzelnesSudoku.addCell(untereZelle);
    return einzelnesSudoku;
}

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private void setBorder(PdfPCell cell, boolean first, boolean last) {
    if (cell == null) {
        return;/*from w  w w  . j av  a 2s.  c o m*/
    }
    if (first) {
        cell.setBorder(PdfPCell.TOP | PdfPCell.BOTTOM | PdfPCell.LEFT);
    } else if (last) {
        cell.setBorder(PdfPCell.TOP | PdfPCell.BOTTOM | PdfPCell.RIGHT);
    } else {
        cell.setBorder(PdfPCell.TOP | PdfPCell.BOTTOM);
    }
}

From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java

License:Open Source License

@SuppressWarnings("hiding")
public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException {
    boolean result = false;
    UnitTrayLabel label = new UnitTrayLabel();
    LabelEncoder encoder = new LabelEncoder(label);
    Image image = encoder.getImage();
    int counter = 0;
    try {/*w  w  w. j  a v a  2s  .  co m*/
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("labels.pdf"));
        document.setPageSize(PageSize.LETTER);
        document.open();

        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100f);
        //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        float[] cellWidths = { 30f, 20f, 30f, 20f };
        table.setWidths(cellWidths);

        UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle();
        if (taxa == null) {
            taxa = uls.findAll();
        }
        Iterator<UnitTrayLabel> i = taxa.iterator();
        PdfPCell cell = null;
        PdfPCell cell_barcode = null;
        // Create two lists of 12 cells, the first 6 of each representing
        // the left hand column of 6 labels, the second 6 of each 
        // representing the right hand column.  
        // cells holds the text for each label, cells_barcode the barcode.
        ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12);
        ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12);
        for (int x = 0; x < 12; x++) {
            cells.add(null);
            cells_barcode.add(null);
        }
        int cellCounter = 0;
        while (i.hasNext()) {
            // Loop through all of the taxa (unit tray labels) found to print 
            label = i.next();
            for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                // For each taxon, loop through the number of requested copies 
                // Generate a text and a barcode cell for each, and add to array for page
                log.debug("Label " + toPrint + " of " + label.getNumberToPrint());
                cell = new PdfPCell();
                cell.setBorderColor(Color.LIGHT_GRAY);
                cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                cell.disableBorderSide(PdfPCell.RIGHT);
                cell.setPaddingLeft(3);

                String higherNames = "";
                if (label.getTribe().trim().length() > 0) {
                    higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe();
                } else {
                    higherNames = label.getFamily() + ": " + label.getSubfamily();
                }
                Paragraph higher = new Paragraph();
                higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                higher.add(new Chunk(higherNames));
                cell.addElement(higher);

                Paragraph name = new Paragraph();
                Chunk genus = new Chunk(label.getGenus().trim() + " ");
                genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                Chunk species = new Chunk(label.getSpecificEpithet().trim());
                Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>)
                if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) {
                    if (label.getSpecificEpithet().startsWith("nr. ")) {
                        normal = new Chunk("nr. ");
                        normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                        species = new Chunk(label.getSpecificEpithet().trim().substring(4));
                        species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                    } else {
                        species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                    }
                } else {
                    species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                }
                String s = "";
                if (label.getSubspecificEpithet().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim());
                if (label.getSubspecificEpithet().contains(".")
                        || label.getSubspecificEpithet().contains("[")) {
                    subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                } else {
                    subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                }
                if (label.getInfraspecificRank().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim());
                infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));

                if (label.getInfraspecificEpithet().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim());
                infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                if (label.getUnNamedForm().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim());
                unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));

                name.add(genus);
                if (normal != null) {
                    name.add(normal);
                }
                name.add(species);
                name.add(subspecies);
                name.add(infraRank);
                name.add(infra);
                name.add(unNamed);
                cell.addElement(name);

                Paragraph authorship = new Paragraph();
                authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                if (label.getAuthorship() != null && label.getAuthorship().length() > 0) {
                    Chunk c_authorship = new Chunk(label.getAuthorship());
                    authorship.add(c_authorship);
                }
                cell.addElement(authorship);
                //cell.addElement(new Paragraph(" "));
                if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) {
                    Paragraph drawerNumber = new Paragraph();
                    drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                    Chunk c_drawerNumber = new Chunk(label.getDrawerNumber());
                    drawerNumber.add(c_drawerNumber);
                    cell.addElement(drawerNumber);
                } else {
                    if (label.getCollection() != null && label.getCollection().length() > 0) {
                        Paragraph collection = new Paragraph();
                        collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                        Chunk c_collection = new Chunk(label.getCollection());
                        collection.add(c_collection);
                        cell.addElement(collection);
                    }
                }

                cell_barcode = new PdfPCell();
                cell_barcode.setBorderColor(Color.LIGHT_GRAY);
                cell_barcode.disableBorderSide(PdfPCell.LEFT);
                cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP);

                encoder = new LabelEncoder(label);
                image = encoder.getImage();
                image.setAlignment(Image.ALIGN_TOP);
                cell_barcode.addElement(image);

                cells.add(cellCounter, cell);
                cells_barcode.add(cellCounter, cell_barcode);

                cellCounter++;
                // If we have hit a full set of 12 labels, add them to the document
                // in two columns, filling left column first, then right
                if (cellCounter == 12) {
                    // add a page of 12 cells in columns of two.
                    for (int x = 0; x < 6; x++) {
                        if (cells.get(x) == null) {
                            PdfPCell c = new PdfPCell();
                            c.setBorder(0);
                            table.addCell(c);
                            table.addCell(c);
                        } else {
                            table.addCell(cells.get(x));
                            table.addCell(cells_barcode.get(x));
                        }
                        if (cells.get(x + 6) == null) {
                            PdfPCell c = new PdfPCell();
                            c.setBorder(0);
                            table.addCell(c);
                            table.addCell(c);
                        } else {
                            table.addCell(cells.get(x + 6));
                            table.addCell(cells_barcode.get(x + 6));
                        }
                    }
                    // Reset to begin next page
                    cellCounter = 0;
                    document.add(table);
                    table = new PdfPTable(4);
                    table.setWidthPercentage(100f);
                    table.setWidths(cellWidths);
                    for (int x = 0; x < 12; x++) {
                        cells.set(x, null);
                        cells_barcode.set(x, null);
                    }
                }
            } // end loop through toPrint (for a taxon)
            counter++;
        } // end while results has next (for all taxa requested)
          // get any remaining cells in pairs
        for (int x = 0; x < 6; x++) {
            if (cells.get(x) == null) {
                PdfPCell c = new PdfPCell();
                c.setBorder(0);
                table.addCell(c);
                table.addCell(c);
            } else {
                table.addCell(cells.get(x));
                table.addCell(cells_barcode.get(x));
            }
            if (cells.get(x + 6) == null) {
                PdfPCell c = new PdfPCell();
                c.setBorder(0);
                table.addCell(c);
                table.addCell(c);
            } else {
                table.addCell(cells.get(x + 6));
                table.addCell(cells_barcode.get(x + 6));
            }
        }
        // add any remaining cells
        document.add(table);
        try {
            document.close();
        } catch (Exception e) {
            throw new PrintFailedException("No labels to print." + e.getMessage());
        }
        // Check to see if there was content in the document.
        if (counter == 0) {
            result = false;
        } else {
            // Printed to pdf ok.
            result = true;
            // Increment number printed.
            i = taxa.iterator();
            while (i.hasNext()) {
                label = i.next();
                for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                    label.setPrinted(label.getPrinted() + 1);
                }
                label.setNumberToPrint(0);
                try {
                    uls.attachDirty(label);
                } catch (SaveFailedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new PrintFailedException("File not found.");
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new PrintFailedException("Error buiding PDF document.");
    } catch (OutOfMemoryError e) {
        System.out.println("Out of memory error. " + e.getMessage());
        System.out.println("Failed.  Too many labels.");
        throw new PrintFailedException("Ran out of memory, too many labels at once.");
    }
    return result;
}

From source file:etc.Exporter.java

License:Open Source License

public static void saveAsPDF(File file, Task task) {
    try {/*w  ww .j a v  a  2  s  .  com*/
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(file));

        document.open();
        Paragraph taskid = new Paragraph("ID e Detyres: " + task.getIdentifier(),
                FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC));
        document.add(taskid);

        Paragraph creator = new Paragraph("Krijuar nga " + task.getCreator().toString() + "["
                + task.getCreationTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy - HH.mm")) + "]",
                FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC));
        document.add(creator);

        Paragraph executor = new Paragraph("Per zbatim prej: " + task.getExecutor().toString(),
                FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC));
        document.add(executor);

        Paragraph title = new Paragraph(task.getTitle().toUpperCase(),
                FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD));
        document.add(title);

        Paragraph description = new Paragraph(task.getDescription(),
                FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL));
        document.add(description);

        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.BOTTOM);

        PdfPTable table = new PdfPTable(1);
        table.addCell(cell);
        table.setWidthPercentage(100f);
        document.add(table);

        if (task instanceof dc.CompletedTask) {
            document.add(new Paragraph(
                    "Gjendja: Perfunduar [" + ((dc.CompletedTask) task).getCompletitionTime()
                            .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)));
            document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(),
                    FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD)));
            document.add(new Paragraph(((dc.CompletedTask) task).getAnnotations(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL)));
        } else if (task instanceof dc.RejectedTask) {
            document.add(new Paragraph(
                    "Gjendja: Refuzuar [" + ((dc.RejectedTask) task).getRejectionTime()
                            .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)));
            document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(),
                    FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD)));
            document.add(new Paragraph(((dc.RejectedTask) task).getAnnotations(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL)));
        } else {
            document.add(new Paragraph("Gjendja: Ne Pritje",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)));
        }

        document.close();

        Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.getAbsolutePath());
        p.waitFor();
    } catch (DocumentException | InterruptedException | IOException ex) {
        Logger.getLogger(Exporter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

private List<ColumnText> fillTable(float height) {
    // copy text for simulation
    List<ColumnText> tt = null;
    if (breakHandlingParent == null && colIdx >= layoutTable.getNumberOfColumns()) {
        // more column breaks than available column
        // we try not to lose content
        // but results may be different than in open office
        // anyway it is logical error made by document creator
        tt = new ArrayList<ColumnText>();
        ColumnText t = createColumnText();
        tt.add(t);/*from  ww w .ja v  a  2 s.  c o m*/
        for (int i = 0; i < texts.size(); i++) {
            PdfPTable table = new PdfPTable(1);
            table.setWidthPercentage(100.0f);
            PdfPCell cell = new PdfPCell();
            cell.setBorder(Table.NO_BORDER);
            cell.setPadding(0.0f);
            cell.setColumn(ColumnText.duplicate(texts.get(i)));
            table.addCell(cell);
            t.addElement(table);
        }
    } else {
        tt = new ArrayList<ColumnText>(texts);
        for (int i = 0; i < tt.size(); i++) {
            tt.set(i, ColumnText.duplicate(tt.get(i)));
        }
    }
    // clear layout table
    clearTable(layoutTable, true);
    setWidthIfNecessary();

    // try to fill cells with text
    ColumnText t = tt.get(0);
    for (PdfPCell cell : layoutTable.getRow(0).getCells()) {
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        cell.setColumn(ColumnText.duplicate(t));
        //
        t.setSimpleColumn(cell.getLeft() + cell.getPaddingLeft(),
                height >= 0.0f ? -height : PdfPRow.BOTTOM_LIMIT, cell.getRight() - cell.getPaddingRight(), 0);
        int res = 0;
        try {
            res = t.go(true);
        } catch (DocumentException e) {
            throw new ODFConverterException(e);
        }
        if (!ColumnText.hasMoreText(res)) {
            // no overflow in current column
            if (tt.size() == 1) {
                // no more text
                return null;
            } else {
                // some text waiting for new column
                tt.remove(0);
                t = tt.get(0);
            }
        }
    }
    return tt;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

public static SectionPdfPTable createLayoutTable(float width, float height,
        List<StyleColumnProperties> columnPropertiesList) {
    // create one row table which will layout section text
    int colCount = columnPropertiesList.size();
    int relativeWidths[] = new int[colCount];
    SectionPdfPTable table = new SectionPdfPTable(colCount);
    // add cells/*from  w w  w. j a va2s  .  com*/
    for (int i = 0; i < colCount; i++) {
        PdfPCell cell = new PdfPCell();
        cell.setBorder(Table.NO_BORDER);
        cell.setPadding(0.0f);
        cell.setColumn(createColumnText());
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        // apply styles to cell
        StyleColumnProperties columnProperties = columnPropertiesList.get(i);
        relativeWidths[i] = columnProperties.getRelWidth();
        cell.setPaddingLeft(
                columnProperties.getStartIndent() != null ? columnProperties.getStartIndent() : 0.0f);
        cell.setPaddingRight(columnProperties.getEndIndent() != null ? columnProperties.getEndIndent() : 0.0f);
        table.addCell(cell);
    }
    replaceTableCells(table);
    // set width
    try {
        table.setWidths(relativeWidths);
    } catch (DocumentException e) {
        throw new ODFConverterException(e);
    }
    table.setTotalWidth(width);
    table.setLockedWidth(true);
    return table;
}