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

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

Introduction

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

Prototype

public int getNumberOfColumns() 

Source Link

Document

Returns the number of columns.

Usage

From source file:com.iucosoft.eavertizare.util.Export.java

public static void toPdf(JFrame frame, JTable jTableClients, String firma) {

    Document document = new Document(PageSize.A4.rotate());
    try {//from   ww w. j  a va 2 s.  co  m
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setDialogTitle("Specify a file to save");

        int userSelection = fileChooser.showSaveDialog(frame);

        if (userSelection == JFileChooser.APPROVE_OPTION) {

            File fileToSave = fileChooser.getSelectedFile();
            System.out.println("Save as file: " + fileToSave.getAbsolutePath());
            PdfWriter.getInstance(document, new FileOutputStream(fileToSave.getAbsolutePath() + ".pdf"));

        }

        document.open();
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();

        if (firma.equals("All firms")) {

            addTitle(document, "Raport pentru toate firmele cu toti clienti \n din " + dateFormat.format(date));
        } else {

            addTitle(document, "Raport pentru " + firma + " \n din " + dateFormat.format(date));
        }

        addEmptyLine(document, new Paragraph(), 2);

        PdfPTable table = new PdfPTable(jTableClients.getColumnCount());
        table.setTotalWidth(jTableClients.getColumnCount() + 780);
        table.setLockedWidth(true);
        table.setHorizontalAlignment(Element.ALIGN_LEFT);

        for (int i = 0; i < table.getNumberOfColumns(); i++) {

            if (jTableClients.getColumnName(i).equals("")) {
                table.addCell("Trimis");
            } else {
                table.addCell(jTableClients.getColumnName(i));
            }
        }
        Object value;
        for (int i = 0; i < jTableClients.getRowCount(); i++) {
            for (int j = 0; j < table.getNumberOfColumns(); j++) {
                value = jTableClients.getValueAt(i, j);
                table.addCell(value.toString());
            }
        }
        document.add(table);
        document.close();

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

From source file:Contabilidad.RCuentas.java

public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo1, int op) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*from w  w  w .j a  v a 2  s. c o  m*/
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));

        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 14);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 570, 0);
        reporte.contenido.setFontAndSize(bf, 8);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        String titulo = titulo1;
        if (op == 1) {
            if (t_fecha3.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " apartir del " + t_fecha3.getText();

            if (t_fecha4.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " al " + t_fecha4.getText();
        }
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 560, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 750, 570, 0);
        if (op == 1) {
            if (valores != null) {
                String val = "Estatus: ";
                if (lista.getSelectedValues().length > 0) {
                    for (int m = 0; m < valores.length; m++) {
                        val += valores[m].toString() + ", ";
                    }
                    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, val, 750, 560, 0);
                } else {
                    for (int mm = 0; mm < lista.getModel().getSize(); mm++) {
                        val += lista.getModel().getElementAt(mm).toString() + ", ";
                    }
                    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, val, 750, 560, 0);
                }
            }
        }

        reporte.finTexto();
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        if (op == 1) {
            for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
                tabla.addCell(reporte.celda(t_datos.getColumnName(a), font, cabecera, centro, 0, 1,
                        Rectangle.RECTANGLE));
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

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

License:Open Source License

@SuppressWarnings("hiding")
public static boolean printList(ArrayList<ContainerLabel> containers) throws PrintFailedException {
    log.debug("Invoked printList ");
    boolean result = false;
    ContainerLabel label = new ContainerLabel();
    if (containers.isEmpty()) {
        log.debug("No labels to print.");
    } else {/*from w ww .ja  va 2 s. com*/
        LabelDefinitionType printDefinition = null;
        LabelDefinitionListType printDefs = PreCaptureSingleton.getInstance().getPrintFormatDefinitionList();
        List<LabelDefinitionType> printDefList = printDefs.getLabelDefinition();
        Iterator<LabelDefinitionType> il = printDefList.iterator();
        while (il.hasNext()) {
            LabelDefinitionType def = il.next();
            if (def.getTitle().equals(PreCaptureSingleton.getInstance().getProperties().getProperties()
                    .getProperty(PreCaptureProperties.KEY_SELECTED_PRINT_DEFINITION))) {
                printDefinition = def;
            }
        }
        if (printDefinition == null) {
            log.error("No selected print format defintion found.");
            //TODO change from message to error handling dialog that allows picking a print format.
            JOptionPane.showMessageDialog(null, "Unable to print.  No print format is selected.");
        } else {

            log.debug(printDefinition.getTitle());
            log.debug(printDefinition.getTextOrentation().toString());

            LabelEncoder encoder = new LabelEncoder(containers.get(0));
            try {
                Image image = encoder.getImage();
                Document document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream(PreCaptureSingleton.getInstance()
                        .getProperties().getProperties().getProperty(PreCaptureProperties.KEY_LABELPRINTFILE)));
                // Convert units in print definition to points (72 points/inch, 28.346456 points/cm)

                int paperWidthPoints = 612; // 8.5"
                int paperHeightPoints = 792; // 11"
                int marginsPoints = 36; // 0.5"
                int labelWidthPoints = 540; // 7.5" 
                int labelHeightPoints = 720; // 10"
                int numColumns = 1; // goes with above

                numColumns = printDefinition.getColumns();
                float relWidthTextCell = printDefinition.getRelWidthTextCell();
                float relWidthBarcodeCell = printDefinition.getRelWidthBarcodeCell();
                log.debug("relWidthTextCell = " + relWidthTextCell);
                log.debug("relWidthBarcodeCell = " + relWidthBarcodeCell);

                if (printDefinition.getUnits().toString().toLowerCase().equals("inches")) {
                    paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 72f);
                    paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 72f);
                    marginsPoints = (int) Math.floor(printDefinition.getMargins() * 72f);
                    labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 72f);
                    labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 72f);
                }
                if (printDefinition.getUnits().toString().toLowerCase().equals("cm")) {
                    paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 28.346456f);
                    paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 28.346456f);
                    marginsPoints = (int) Math.floor(printDefinition.getMargins() * 28.346456f);
                    labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 28.346456f);
                    labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 28.346456f);
                }
                if (printDefinition.getUnits().toString().toLowerCase().equals("points")) {
                    paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 1f);
                    paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 1f);
                    marginsPoints = (int) Math.floor(printDefinition.getMargins() * 1f);
                    labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 1f);
                    labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 1f);
                }

                if (paperWidthPoints == 612 && paperHeightPoints == 792) {
                    document.setPageSize(PageSize.LETTER);
                } else {
                    document.setPageSize(new Rectangle(paperWidthPoints, paperHeightPoints));
                }
                document.setMargins(marginsPoints, marginsPoints, marginsPoints, marginsPoints);
                document.open();

                // Sanity check
                if (paperWidthPoints <= 0) {
                    paperWidthPoints = 612;
                }
                if (paperHeightPoints <= 0) {
                    paperHeightPoints = 792;
                }
                if (marginsPoints < 0) {
                    marginsPoints = 0;
                }
                if (labelWidthPoints <= 0) {
                    labelWidthPoints = 540;
                }
                if (labelHeightPoints <= 0) {
                    labelHeightPoints = 720;
                }
                if (paperWidthPoints + (marginsPoints * 2) < labelWidthPoints) {
                    labelWidthPoints = paperWidthPoints + (marginsPoints * 2);
                    log.debug("Adjusting label width to fit printable page width");
                }
                if (paperHeightPoints + (marginsPoints * 2) < labelHeightPoints) {
                    labelHeightPoints = paperHeightPoints + (marginsPoints * 2);
                    log.debug("Adjusting label height to fit printable page height");
                }

                // calculate how many columns will fit on the paper.
                int columns = (int) Math.floor((paperWidthPoints - (marginsPoints * 2)) / labelWidthPoints);
                // if specified column count is smaller, use the specified.
                if (numColumns < columns) {
                    columns = numColumns;
                    log.debug(
                            "Fewer columns specified in definition than will fit on page, using specified column count of "
                                    + numColumns);
                }

                // define two table cells per column, one for text one for barcode.
                int subCellColumnCount = columns * 2;

                // set the table, with an absolute width and relative widths of the cells in the table;
                PdfPTable table = setupTable(paperWidthPoints, marginsPoints, labelWidthPoints, columns,
                        subCellColumnCount, relWidthTextCell, relWidthBarcodeCell);
                // figure out the width of the cells containing the barcodes.
                float ratio = ((float) relWidthBarcodeCell)
                        / (((float) relWidthBarcodeCell) + ((float) relWidthTextCell));
                float barcodeCellWidthPoints = (float) Math.floor(labelWidthPoints * ratio);
                log.debug("Width of barcode cell in points: " + barcodeCellWidthPoints);

                //Rectangle pageSizeRectangle = new Rectangle(paperWidthPoints, paperHeightPoints);
                //table.setWidthPercentage(cellWidthsPoints, pageSizeRectangle);
                //table.setTotalWidth(cellWidthsPoints);

                // Calculate how many cells fit on a page (two cells per label).
                int labelsPerColumn = (int) Math
                        .floor((paperHeightPoints - (marginsPoints * 2)) / labelHeightPoints);
                int cellsPerPage = subCellColumnCount * labelsPerColumn;
                log.debug("Labels per column = " + labelsPerColumn);
                log.debug("Cells per page = " + cellsPerPage);

                Iterator<ContainerLabel> iterLabels = containers.iterator();

                int cellCounter = 0; // counts number of cells filled on a page.
                int counter = 0; // counts number of pre capture label data rows to print (each of which may request more than one copy).

                // TODO: Doesn't fit on page.

                while (iterLabels.hasNext()) {
                    // Loop through all of the container labels found to print 
                    label = iterLabels.next();
                    if (label != null) {
                        log.debug(label);
                        log.debug("Label: " + counter + " " + label.toString());
                        for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                            // For each container label, loop through the number of requested copies 
                            // Generate a text and a barcode cell for each, and add to array for page
                            int toPrintPlus = toPrint + 1; // for pretty counter in log.
                            log.debug("Copy " + toPrintPlus + " of " + label.getNumberToPrint());

                            PdfPCell cell = label.toPDFCell(printDefinition);
                            cell.setFixedHeight(labelHeightPoints);
                            // Colors to illustrate where the cells are on the layout
                            if (PreCaptureSingleton.getInstance().getProperties().getProperties()
                                    .getProperty(PreCaptureProperties.KEY_DEBUGLABEL).equals("true")) {
                                cell.setBackgroundColor(new BaseColor(255, 255, 30));
                            }

                            PdfPCell cell_barcode = new PdfPCell();
                            cell_barcode.setBorderColor(BaseColor.LIGHT_GRAY);
                            cell_barcode.disableBorderSide(PdfPCell.LEFT);
                            cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                            cell_barcode.setHorizontalAlignment(Element.ALIGN_RIGHT);
                            cell_barcode.setFixedHeight(labelHeightPoints);
                            if (PreCaptureSingleton.getInstance().getProperties().getProperties()
                                    .getProperty(PreCaptureProperties.KEY_DEBUGLABEL).equals("true")) {
                                cell_barcode.setBackgroundColor(new BaseColor(255, 30, 255));
                            }

                            encoder = new LabelEncoder(label);
                            image = encoder.getImage();
                            image.setAlignment(Image.ALIGN_TOP);
                            //image.setAlignment(Image.ALIGN_LEFT);
                            image.setAlignment(Image.ALIGN_RIGHT);
                            image.scaleToFit(barcodeCellWidthPoints, labelHeightPoints);
                            cell_barcode.addElement(image);

                            table.addCell(cell);
                            table.addCell(cell_barcode);

                            cellCounter = cellCounter + 2; // we've added two cells to the page (two cells per label).
                            log.debug("Cells " + cellCounter + " of " + cellsPerPage + " cells per page.");

                            // If we have hit a full set of labels for the page, add them to the document
                            // in each column, filling left to right
                            if (cellCounter >= cellsPerPage - 1) {
                                log.debug("Page is full");
                                log.debug("Table has " + table.getNumberOfColumns() + " columns and "
                                        + table.getRows().size() + " rows ");
                                // Reset to begin next page
                                cellCounter = 0;
                                table.setLockedWidth(true);
                                document.add(table);
                                log.debug("Adding new page");
                                document.newPage();
                                table = setupTable(paperWidthPoints, marginsPoints, labelWidthPoints, columns,
                                        subCellColumnCount, relWidthTextCell, relWidthBarcodeCell);
                                log.debug("Setup new table");
                            }
                        } // end loop through toPrint (for a taxon/precapture label data row)
                        counter++; // Increment number of pre capture label data rows.
                    } // end if not null label
                } // end while results has next (for all taxa requested)
                  // get any remaining cells in pairs
                if (cellCounter > 0) {
                    log.debug("Adding remaining cells in partial page");
                    if (cellCounter <= cellsPerPage) {
                        for (int i = cellCounter; i <= cellsPerPage; i++) {
                            PdfPCell emptyCell = new PdfPCell();
                            emptyCell.setBorder(PdfPCell.NO_BORDER);
                            table.addCell(emptyCell);
                        }
                    }
                    log.debug("Table has " + table.getNumberOfColumns() + " columns and "
                            + table.getRows().size() + " rows ");
                    table.setLockedWidth(true);
                    document.add(table);
                }
                document.close();

                // send to printer
                PrintingUtility.sendPDFToPrinter(printDefinition, paperWidthPoints, paperHeightPoints);

                // Check to see if there was content in the document.
                if (counter == 0) {
                    result = false;
                } else {
                    // Printed to pdf ok.
                    result = true;
                }
            } catch (FileNotFoundException e) {
                log.debug(e.getMessage(), e);
                throw new PrintFailedException("File not found.");
            } catch (DocumentException e) {
                log.error(e.getMessage(), e);
                throw new PrintFailedException("Error building/printing PDF document. " + e.getMessage());
            } 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.");
            } catch (BarcodeCreationException e) {
                System.out.println("BarcodeCreationException. " + e.getMessage());
                System.out.println("Failed.  Couldn't create barcode.");
                throw new PrintFailedException(
                        "Unable to create barcode.  Probably too many characters to encode. " + e.getMessage());
            }
        }
        log.debug("printList Done. Success = " + result);
    }
    return result;
}

From source file:es.baudlord.pcpartpicker.model.Build.java

License:Open Source License

public PdfPTable createPdfPTable(Font font) throws DocumentException {
    List<PdfPCell> cellList = new ArrayList<>();

    cellList.addAll(Arrays.asList(new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Name"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.UnitPrice"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Amount"), font)),
            new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Price"), font))));

    for (Product.Category c : Product.Category.values()) {
        ArrayList<Part> parts = getParts(c);
        if (parts.isEmpty())
            continue;

        parts.forEach(product -> cellList
                .addAll(Arrays.asList(new PdfPCell(new Phrase(product.getDescription(), font)),
                        new PdfPCell(new Phrase(Coin.formatNet(product.getPrice()), font)),
                        new PdfPCell(new Phrase(String.valueOf(product.getAmount()), font)),
                        new PdfPCell(new Phrase(Coin.formatNet(product.getTotalPrice()), font)))));
    }// w  ww.  j  ava  2  s. c  o m
    PdfPCell line = new PdfPCell(new Phrase(""));
    line.setColspan(4);
    cellList.add(line);

    double totalPrice = this.getTotalPrice();
    font.setSize(font.getSize() + 2);

    PdfPCell total = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.price").toUpperCase(), font));
    total.setColspan(3);
    cellList.addAll(Arrays.asList(total, new PdfPCell(new Phrase(Coin.formatNet(totalPrice), font))));

    PdfPCell totalTax = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.tax").toUpperCase(), font));
    totalTax.setColspan(3);
    cellList.addAll(Arrays.asList(totalTax, new PdfPCell(new Phrase(Coin.formatTax(totalPrice), font))));

    PdfPCell totalPvp = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.pvp").toUpperCase(), font));
    totalPvp.setColspan(3);
    cellList.addAll(Arrays.asList(totalPvp, new PdfPCell(new Phrase(Coin.formatGross(totalPrice), font))));

    PdfPTable table = new PdfPTable(4);
    table.setWidths(new int[] { 50, 10, 5, 10 });
    table.setHeaderRows(1);

    for (int i = 0; i < table.getNumberOfColumns(); i++) {
        cellList.get(i).setBorder(Rectangle.BOTTOM);
        table.addCell(cellList.get(i));
    }
    for (int i = table.getNumberOfColumns(); i < cellList.size() - 6; i++) {
        cellList.get(i).setBorder(0);
        table.addCell(cellList.get(i));
    }
    for (int i = cellList.size() - 6; i < cellList.size() - 4; i++) {
        cellList.get(i).setBorder(Rectangle.TOP);
        table.addCell(cellList.get(i));
    }
    for (int i = cellList.size() - 4; i < cellList.size(); i++) {
        cellList.get(i).setBorder(0);
        table.addCell(cellList.get(i));
    }

    return table;
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected void addTableCaption(PdfPTable table, String caption) {

    PdfPCell cell = getContentCell();/*  www . j av a2s . c  o m*/
    cell.setColspan(table.getNumberOfColumns());
    table.addCell(cell);
    PdfPCell captionCell = new PdfPCell(new Phrase(caption, TABLE_CAPTION));
    captionCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    captionCell.setPaddingBottom(5);
    captionCell.setBorder(Rectangle.TOP);
    captionCell.setBorderWidthTop(1.5f);
    captionCell.setPaddingBottom(7);
    captionCell.setPaddingTop(2);
    captionCell.setColspan(table.getNumberOfColumns());
    table.addCell(captionCell);
}

From source file:fxml.test.PDFService.java

public PdfPTable createTableHeader(int start) {

    PdfPTable table = null;

    try {//w  w w  .  ja v  a  2 s . c om

        int colCount = 1;
        List<Float> columnsList = new ArrayList<>();

        columnsList.add(57.5f);
        columnsList.add(159.4f);

        for (int i = start; i < list.size(); i++) {

            if (list.get(i) instanceof Course) {

                columnsList.add(44f);

            } else if (list.get(i).equals("Total Credit")) {

                columnsList.add(30f);

            } else if (list.get(i).equals("Total GPA")) {

                columnsList.add(30f);

            } else if (list.get(i).equals("Letter Grade")) {

                columnsList.add(30f);

            } else if (list.get(i).equals("Cumulative")) {

                columnsList.add(88f);

            } else {

                columnsList.add(66f);

            }

            if (colCount == 12) {
                break;
            }
            colCount++;

        }

        float[] columns = new float[columnsList.size()];

        for (int i = 0; i < columnsList.size(); i++) {
            columns[i] = columnsList.get(i);
        }

        table = new PdfPTable(columns.length);

        System.err.println("table size :" + table.getNumberOfColumns());

        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setTotalWidth(columns);
        table.setLockedWidth(true);

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

    PdfPCell regCell = getCellForString("Reg No.", 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9,
            false);
    regCell.setPaddingTop(0f);
    table.addCell(regCell);

    PdfPCell nameCell = getNameCell();
    nameCell.setPaddingBottom(2f);
    table.addCell(nameCell);

    int colCount = 1;

    for (int i = start; i < list.size(); i++) {

        if (list.get(i) instanceof Course) {

            Course course = (Course) list.get(i);

            PdfPCell cell3 = new PdfPCell(createCourseInfo(course));
            cell3.setPaddingTop(1f);
            cell3.setPaddingBottom(2f);
            //cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell3);

        } else if (list.get(i).equals("Total Credit") || list.get(i).equals("Total GPA")
                || list.get(i).equals("Letter Grade")) {

            String str = (String) list.get(i);
            String s[] = str.split(" ");

            PdfPTable totalCredit = new PdfPTable(1);
            totalCredit.setSpacingBefore(12.5f);
            totalCredit.setWidthPercentage(100);
            totalCredit.getDefaultCell().setBorder(Rectangle.NO_BORDER);

            PdfPCell cell1 = getCellForString(s[0], 0, false, 0, Element.ALIGN_CENTER,
                    new Font(Font.FontFamily.TIMES_ROMAN, 10f), false);
            PdfPCell cell2 = getCellForString(s[1], 0, false, 0, Element.ALIGN_CENTER,
                    new Font(Font.FontFamily.TIMES_ROMAN, 10f), false);

            totalCredit.addCell(cell1);
            totalCredit.addCell(cell2);

            PdfPCell grade = new PdfPCell(totalCredit);
            table.addCell(grade);

        } else if (list.get(i).equals("Cumulative")) {

            PdfPTable cumulative = new PdfPTable(1);
            // cumulative.setPaddingTop(count);
            cumulative.addCell(getCellForString("Cumulative", 0, false, Element.ALIGN_MIDDLE,
                    Element.ALIGN_CENTER, font10, true));

            PdfPTable creditGpaGrade = new PdfPTable(3);

            creditGpaGrade.setTotalWidth(88f);
            creditGpaGrade.setLockedWidth(true);
            creditGpaGrade.addCell(getCellForString("Credit", 0, false, Element.ALIGN_MIDDLE,
                    Element.ALIGN_CENTER, font10, true));
            creditGpaGrade.addCell(getCellForString("GPA", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER,
                    font10, true));
            creditGpaGrade.addCell(getCellForString("Grade", 0, false, Element.ALIGN_MIDDLE,
                    Element.ALIGN_CENTER, font10, true));

            PdfPTable p = new PdfPTable(1);
            PdfPCell cell1 = new PdfPCell(cumulative);
            cell1.setPaddingBottom(3f);
            cell1.setBorder(Rectangle.NO_BORDER);
            PdfPCell cell2 = new PdfPCell(creditGpaGrade);
            cell2.setBorder(Rectangle.NO_BORDER);
            p.addCell(cell1);
            p.addCell(cell2);
            table.addCell(p);

        } else {

            table.addCell(getCellForString((String) list.get(i), 0, true, Element.ALIGN_MIDDLE,
                    Element.ALIGN_CENTER, font9, true));

        }

        if (colCount == 12) {
            break;
        }
        colCount++;
    }

    return table;

}

From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java

License:Open Source License

private void addCellAndCompleteRow(PdfPTable table, PdfPCell cell) {
    table.addCell(cell);//from ww w.jav  a  2  s  . c  o m
    for (int i = 0; i < table.getNumberOfColumns() - 1; i++) {
        addToTable(table, new Paragraph());
    }
}

From source file:org.ganttproject.impex.htmlpdf.itext.ThemeImpl.java

License:GNU General Public License

private void addEmptyRow(PdfPTable table, float height) {
    PdfPCell emptyCell = new PdfPCell(new Paragraph("  ", getSansRegular(height)));
    emptyCell.setBorderWidth(0);/*from w  w w  .j  a  v  a 2 s  .co  m*/
    for (int i = 0; i < table.getNumberOfColumns(); i++) {
        table.addCell(emptyCell);
    }
}

From source file:Valuacion.Reportes.java

public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*www . j a v a 2  s . com*/
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));

        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 14);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 575, 0);
        reporte.contenido.setFontAndSize(bf, 8);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        String titulo = "Reporte";
        if (c_tipo_fecha.getSelectedItem().toString().compareTo("Seleccione") != 0) {
            titulo += " " + c_tipo_fecha.getSelectedItem().toString();
            if (t_fecha1.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " del " + t_fecha1.getText();
            if (t_fecha2.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " al " + t_fecha2.getText();
        }
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 565, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 750, 575, 0);

        reporte.finTexto();
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));
        /*reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));*/
        //reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
            tabla.addCell(
                    reporte.celda(t_datos.getColumnName(a), font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}