Example usage for com.itextpdf.text.pdf PdfPTable addCell

List of usage examples for com.itextpdf.text.pdf PdfPTable addCell

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable addCell.

Prototype

public void addCell(final Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

From source file:com.solidmaps.webapp.report.LicenseCivilIncludeProductPDF.java

License:Open Source License

private void insertCell(PdfPTable table, String text, int align, Font font, boolean border) {

    if (text == null) {
        text = "";
    }//from   ww  w . j  av a2 s. c o  m

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
    // set the cell alignment
    cell.setHorizontalAlignment(align);
    // in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    if (!border) {
        cell.setBorder(Rectangle.NO_BORDER);
    }

    // add the call to the table
    table.addCell(cell);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void createTable(Document doc, RequerimentFederalEnum type, LicensePFEntity license,
        List<ProductOfficialEntity> listProducts) throws DocumentException {

    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(4);
    // set table width a percentage of the page width
    table.setWidthPercentage(100f);/*from  w  w w .j a  v  a 2 s. c  o  m*/

    this.createCompany(table, license);

    // Alterao Cadastral
    this.createAlteracaoCadastral(table, type);

    // Descrio
    this.insertHeaderCell(table, "3 - DESCREVER AS PRINCIPAIS ALTERAES OCORRIDAS", 4);
    this.insertCell(table, this.createProductsText(listProducts, type), 4);

    // Uso Oficial
    this.insertCellProtocol(table, license);

    // Footer
    this.createFooter(table);

    // Table pai
    PdfPTable tableFather = new PdfPTable(1);
    tableFather.setWidthPercentage(100f);
    PdfPCell cellFather = new PdfPCell(table);
    cellFather.setBorderWidth(2);
    tableFather.addCell(cellFather);

    doc.add(this.createHeader());
    doc.add(tableFather);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void createFooter(PdfPTable table) {
    this.insertHeaderCell(table, "Portaria 1.274/03", 4);

    Paragraph artigo = new Paragraph("Art. 6", FONT_HEADER);
    Paragraph text1 = new Paragraph(
            "A pessoa jurdica possuidora de Certificado de Registro Cadastral dever", FONT_PARAGRAPH);
    Paragraph text2 = new Paragraph(" comunicar ao DPF, no prazo de trinta dias, todo e qualquer "
            + "fato que justifique a atualizao de seu cadastro", FONT_HEADER);
    Paragraph text3 = new Paragraph(
            ", mediante preenchimento de formulrio prprio (Anexo VI). " + SEPARATOR_DOUBLE, FONT_PARAGRAPH);

    Paragraph text4 = new Paragraph("Pargrafo nico", FONT_HEADER);
    Paragraph text5 = new Paragraph("O pedido de atualizao do registro cadastral dever ser",
            FONT_PARAGRAPH);//from w w w  .j  a  v  a 2s.co  m
    Paragraph text6 = new Paragraph(
            "formalizado no prazo mximo de noventa dias, a partir da data do comunicado", FONT_HEADER);
    Paragraph text7 = new Paragraph(" a que se refere o caput, por meio de requerimento (Anexo IV).",
            FONT_PARAGRAPH);

    Paragraph paragraphFull = new Paragraph();
    paragraphFull.add(artigo);
    paragraphFull.add(text1);
    paragraphFull.add(text2);
    paragraphFull.add(text3);
    paragraphFull.add(text4);
    paragraphFull.add(text5);
    paragraphFull.add(text6);
    paragraphFull.add(text7);

    PdfPCell cell = new PdfPCell(paragraphFull);
    cell.setColspan(4);

    table.addCell(cell);

}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCell(PdfPTable table, String text, Integer colSpan) {

    if (text == null) {
        text = "";
    }//from  www  .  j a v  a  2s  .  c o  m

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_PARAGRAPH));
    // set the cell alignment
    // in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setColspan(colSpan);
    cell.setPadding(5f);

    // add the call to the table
    table.addCell(cell);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCellProtocol(PdfPTable table, LicensePFEntity license) {

    PdfPTable tableProtocol = new PdfPTable(1);
    tableProtocol.setWidthPercentage(100f);

    Paragraph officialPhrase = new Paragraph("USO OFICIAL" + SEPARATOR, FONT_PARAGRAPH);
    officialPhrase.setAlignment(Element.ALIGN_LEFT);

    Paragraph protocolPhrase = new Paragraph("ETIQUETA PROTOCOLO" + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE
            + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR, FONT_PROTOCOL);
    protocolPhrase.setAlignment(Element.ALIGN_LEFT);

    Paragraph obsPhrase = new Paragraph("Observao Importante!" + SEPARATOR, FONT_HEADER);

    Paragraph obsStringPhrase = new Paragraph(
            "Protocolar este Anexo somente quando no conjugado com a alterao efetiva ou a renovao da licena.",
            FONT_PARAGRAPH);/*from w ww. j  a  v  a 2  s .  c o m*/

    Paragraph fullPhrase = new Paragraph();
    fullPhrase.add(officialPhrase);
    fullPhrase.add(protocolPhrase);
    fullPhrase.add(obsPhrase);
    fullPhrase.add(obsStringPhrase);

    PdfPCell cell = new PdfPCell(fullPhrase);

    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(5f);

    tableProtocol.addCell(cell);

    PdfPCell cellProtocol = new PdfPCell(tableProtocol);
    cellProtocol.setColspan(2);

    table.addCell(cellProtocol);
    table.addCell(this.createCellEtiqueta(license));
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCellAlteracao(PdfPTable table, String text) {

    if (text == null) {
        text = "";
    }/*from  ww w  .  j  ava2s  .  co  m*/

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_HEADER));
    // set the cell alignment
    // in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setColspan(2);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);

    // add the call to the table
    table.addCell(cell);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCellAlteracaoOption(PdfPTable table, String number, String text, Boolean selected) {

    String fullText = "";
    if (selected) {
        fullText += number + " |X|" + " " + text;
    } else {//from www .j  av  a2s. c  om
        fullText += number + " |  |" + " " + text;
    }

    if (StringUtils.isBlank(number) && StringUtils.isBlank(text)) {
        fullText = "";
    }

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(fullText.trim(), FONT_PARAGRAPH));
    // set the cell alignment
    // in case there is no text and you wan to create an empty row
    if (fullText.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setColspan(2);
    cell.setBorder(Rectangle.RIGHT);
    cell.setPaddingTop(10f);
    cell.setPaddingBottom(10f);
    cell.setPaddingLeft(25f);
    cell.setPaddingRight(25f);

    // add the call to the table
    table.addCell(cell);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertHeaderCell(PdfPTable table, String text, Integer colSpan) {

    if (text == null) {
        text = "";
    }//from   w  ww.j  a  v a 2  s  .  c  om

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_HEADER));
    // set the cell alignment
    // in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    cell.setVerticalAlignment(Element.ALIGN_CENTER);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setColspan(colSpan);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorderWidth(2);
    cell.setPadding(3f);

    // add the call to the table
    table.addCell(cell);
}

From source file:com.systemevent.jsfclass.util.PdfEvento.java

public PdfPTable Tabla_compleja() {
    //creamos una tabla con 3 columnas
    PdfPTable mitablacompleja = new PdfPTable(3);
    //aadimos texto con formato a la primera celda
    PdfPCell celda = new PdfPCell(new Paragraph("Historial de Observaciones", FontFactory.getFont("arial", // fuente
            22, // tamao
            Font.BOLD, // estilo
            BaseColor.RED))); // color
    //unimos esta celda con otras 2
    celda.setColspan(3);/* w ww .  ja va2 s .  c  om*/
    //alineamos el contenido al centro
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    // aadimos un espaciado
    celda.setPadding(12.0f);
    //colocamos un color de fondo
    celda.setBackgroundColor(BaseColor.GRAY);
    //se aade a la tabla
    mitablacompleja.addCell(celda);

    //fila 2
    celda = new PdfPCell(new Paragraph("AUDITORIA DE SISTEMAS"));
    celda.setColspan(2);
    celda.setBackgroundColor(BaseColor.GREEN);
    mitablacompleja.addCell(celda);
    celda = new PdfPCell(new Paragraph("Aprobado"));
    celda.setBackgroundColor(BaseColor.LIGHT_GRAY);
    mitablacompleja.addCell(celda);
    //fila 3        
    celda = new PdfPCell(new Paragraph("COMPILADORES"));
    celda.setColspan(2);
    celda.setBackgroundColor(BaseColor.YELLOW);
    mitablacompleja.addCell(celda);
    celda = new PdfPCell(new Paragraph("Reprobado"));
    celda.setBackgroundColor(BaseColor.LIGHT_GRAY);
    mitablacompleja.addCell(celda);
    //fila 4        
    celda = new PdfPCell(new Paragraph("Prog. Bajo Nivel"));
    celda.setColspan(2);
    celda.setBackgroundColor(BaseColor.CYAN);
    mitablacompleja.addCell(celda);
    celda = new PdfPCell(new Paragraph("Eximido"));
    celda.setBackgroundColor(BaseColor.LIGHT_GRAY);
    mitablacompleja.addCell(celda);
    //fila 5
    mitablacompleja.addCell("Conclusion");
    celda = new PdfPCell(new Paragraph("GET A LIFE!!!"));
    celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
    celda.setColspan(2);
    celda.setBackgroundColor(BaseColor.ORANGE);
    mitablacompleja.addCell(celda);
    // se retorna la tabla

    return mitablacompleja;
}

From source file:com.thelinh.gui.PreviewExam.java

private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed
    if (this.txtExamCode.getText().equals("")) {
        JOptionPane.showMessageDialog(this, "Hy nhp m ?");
    } else {//from  w w w. j  a  v a 2s. c o  m
        JFileChooser fc = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF files (*.pdf)", "pdf");
        fc.setFileFilter(filter);
        int rt = fc.showSaveDialog(this);
        if (rt == JFileChooser.APPROVE_OPTION) {
            String filepath = fc.getSelectedFile().getPath();
            if (filepath.indexOf(".") == -1) {
                filepath = filepath + ".pdf";
            }
            String dafilepath = (new StringBuffer(filepath)).insert(filepath.length() - 4, ".da").toString();
            try {
                Document document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream(filepath));
                document.open();

                // Add title
                Paragraph p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25);
                p.setAlignment(Element.ALIGN_CENTER);
                p.setSpacingAfter(5);
                document.add(p);

                p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25);
                p.setAlignment(Element.ALIGN_CENTER);
                p.setSpacingAfter(25);
                document.add(p);

                p = new Paragraph(
                        "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName()
                                + ", Ngy ra ?: "
                                + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())),
                        times_15);
                p.setAlignment(Element.ALIGN_LEFT);
                p.setSpacingAfter(5);
                document.add(p);

                p = new Paragraph("M ?: " + this.txtExamCode.getText() + "    Th?i gian lm bi: "
                        + spTime.getValue().toString() + " pht", timesBold_15);
                p.setSpacingAfter(25);
                document.add(p);

                for (int i = 0; i < this.questionList.size(); i++) {
                    Question question = this.questionList.get(i);
                    ArrayList<Answer> answerList = AnswerSql
                            .getAnswersByQuestionId(question.getQuestionId().trim());
                    Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15);
                    Phrase questionContent = new Phrase(question.getQuestion(), times_15);

                    Paragraph questionTitle = new Paragraph();
                    questionTitle.add(questionNumber);
                    questionTitle.add(questionContent);

                    document.add(questionTitle);
                    PdfPTable table = new PdfPTable(2);

                    for (int j = 0; j < answerList.size(); j++) {
                        Answer ans = answerList.get(j);
                        Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15);
                        Phrase answerContent = new Phrase(ans.getAnswer(), times_15);
                        Phrase elem = new Phrase();
                        elem.add(cap);
                        elem.add(answerContent);
                        PdfPCell cell = new PdfPCell();

                        cell.setBorder(Rectangle.NO_BORDER);
                        cell.setPhrase(elem);
                        cell.setFixedHeight(25);
                        table.addCell(cell);
                    }
                    document.add(table);
                }
                document.close();
                //                    if (Desktop.isDesktopSupported()) {
                //                        try {
                //                            File myFile = new File(filepath);
                //                            Desktop.getDesktop().open(myFile);
                //                        } catch (IOException ex) {
                //                            // no application registered for PDFs
                //                            System.out.println(ex.toString());
                //                        }
                //                    }

                document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream(dafilepath));
                document.open();

                // Add title
                p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25);
                p.setAlignment(Element.ALIGN_CENTER);
                p.setSpacingAfter(5);
                document.add(p);

                p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25);
                p.setAlignment(Element.ALIGN_CENTER);
                p.setSpacingAfter(25);
                document.add(p);

                p = new Paragraph(
                        "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName()
                                + ", Ngy ra ?: "
                                + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())),
                        times_15);
                p.setAlignment(Element.ALIGN_LEFT);
                p.setSpacingAfter(5);
                document.add(p);

                p = new Paragraph("M ?: " + this.txtExamCode.getText() + "    Th?i gian lm bi: "
                        + spTime.getValue().toString() + " pht", timesBold_15);
                p.setSpacingAfter(25);
                document.add(p);

                for (int i = 0; i < this.questionList.size(); i++) {
                    Question question = this.questionList.get(i);
                    ArrayList<Answer> answerList = AnswerSql
                            .getAnswersByQuestionId(question.getQuestionId().trim());
                    Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15);
                    Phrase questionContent = new Phrase(question.getQuestion(), times_15);

                    Paragraph questionTitle = new Paragraph();
                    questionTitle.add(questionNumber);
                    questionTitle.add(questionContent);

                    document.add(questionTitle);
                    PdfPTable table = new PdfPTable(2);

                    for (int j = 0; j < answerList.size(); j++) {
                        Answer ans = answerList.get(j);
                        Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15);
                        Phrase answerContent = null;
                        if (ans.getYesNo()) {
                            answerContent = new Phrase(ans.getAnswer(), timesBold_15);
                        } else {
                            answerContent = new Phrase(ans.getAnswer(), times_15);
                        }
                        Phrase elem = new Phrase();
                        elem.add(cap);
                        elem.add(answerContent);
                        PdfPCell cell = new PdfPCell();

                        cell.setBorder(Rectangle.NO_BORDER);
                        cell.setPhrase(elem);
                        cell.setFixedHeight(25);
                        table.addCell(cell);
                    }
                    document.add(table);
                }
                document.close();

            } catch (FileNotFoundException | DocumentException ex) {
                Logger.getLogger(PreviewExam.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}