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.cs.sis.controller.gerador.GeradorPDF.java

private PdfPTable getTableBalancoProdutos(Date inicio, Date fim) throws DocumentException {
    Map<String, Double[]> saida = GeradorRelatorio.getRelatorioDetalhadoSaidaProduto(inicio, fim);

    PdfPTable table = new PdfPTable(5);
    table.setWidths(new int[] { 5, 1, 1, 1, 1 });
    table.setWidthPercentage(100f);/* w  w w.  ja v a  2  s. c o  m*/
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);

    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell("Produto");
    table.addCell("Estoque");
    table.addCell("Compra");
    table.addCell("Venda");
    table.addCell("Lucro");
    table.getDefaultCell().setBackgroundColor(null);
    double compra = 0, venda = 0, lucro = 0, qt = 0;
    List<String> c = new ArrayList<String>();
    c.addAll(saida.keySet());
    Collections.sort(c);
    for (String produto : c) {
        table.addCell(produto);
        Double[] val = saida.get(produto);
        compra += val[0];
        venda += val[1];
        lucro += val[3];
        qt += val[2];
        table.addCell(new DecimalFormat("0.000").format(val[2]));
        table.addCell(new DecimalFormat("0.00").format(val[0]));
        table.addCell(new DecimalFormat("0.00").format(val[1]));
        table.addCell(new DecimalFormat("0.00").format(val[3]));
    }

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));

    PdfPCell cell = new PdfPCell(new Paragraph("Total"));
    cell.setColspan(5);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell(cell);

    table.addCell(saida.size() + " Produtos");

    table.addCell(new DecimalFormat("0.000").format(qt));
    table.addCell(new DecimalFormat("0.00").format(compra));
    table.addCell(new DecimalFormat("0.00").format(venda));
    table.addCell(new DecimalFormat("0.00").format(lucro));

    return table;
}

From source file:com.cs.sis.controller.gerador.GeradorPDF.java

private PdfPTable getTableDebitoClientes(double maiorQue) throws DocumentException {
    List<Object[]> debitos = GeradorRelatorio.getRelatorioClientesComDebitoMaiorQue(maiorQue);

    PdfPTable table = new PdfPTable(2);
    table.setWidths(new int[] { 5, 2 });
    table.setWidthPercentage(100f);//from w  w w .j  a va2s. c  om
    table.setSpacingBefore(10f);
    table.setSpacingAfter(10f);

    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell("Cliente");
    table.addCell("Dbito");
    table.getDefaultCell().setBackgroundColor(null);
    double total = 0;
    for (Object[] d : debitos) {
        table.addCell((String) d[0]);
        double val = (double) d[1];
        table.addCell(OperacaoStringUtil.formatarStringValorMoedaEPonto(val));
        total += val;
    }

    table.getDefaultCell().setBackgroundColor(new BaseColor(60, 171, 198));

    PdfPCell cell = new PdfPCell(new Paragraph("Total"));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(new BaseColor(60, 171, 198));
    table.addCell(cell);

    table.addCell(OperacaoStringUtil.formatarStringValorMoedaComDescricaoEPonto(total));

    table.addCell("Quantidade de Clientes");
    table.addCell(OperacaoStringUtil.formatarStringValorInteger(debitos.size()));

    return table;
}

From source file:com.dandymadeproductions.ajqvue.io.PDFDataTableDumpThread.java

License:Open Source License

public void run() {
    // Class Method Instances
    String title;//from w  w w  .  j a  v  a  2  s. c  o m

    Font titleFont;
    Font rowHeaderFont;
    Font tableDataFont;
    BaseFont rowHeaderBaseFont;

    PdfPTable pdfTable;
    PdfPCell titleCell;
    PdfPCell rowHeaderCell;
    PdfPCell bodyCell;

    Document pdfDocument;
    PdfWriter pdfWriter;
    ByteArrayOutputStream byteArrayOutputStream;

    int columnCount, rowNumber;
    int[] columnWidths;
    int totalWidth;
    Rectangle pageSize;

    ProgressBar dumpProgressBar;
    HashMap<String, String> summaryListTableNameTypes;
    DataExportProperties pdfDataExportOptions;

    String currentTableFieldName;
    String currentType, currentString;

    // Setup
    columnCount = summaryListTable.getColumnCount();
    rowNumber = summaryListTable.getRowCount();
    columnWidths = new int[columnCount];

    pdfTable = new PdfPTable(columnCount);
    pdfTable.setWidthPercentage(100);
    pdfTable.getDefaultCell().setPaddingBottom(4);
    pdfTable.getDefaultCell().setBorderWidth(1);

    summaryListTableNameTypes = new HashMap<String, String>();
    pdfDataExportOptions = DBTablesPanel.getDataExportProperties();

    titleFont = new Font(pdfDataExportOptions.getFont());
    titleFont.setStyle(Font.BOLD);
    titleFont.setSize((float) pdfDataExportOptions.getTitleFontSize());
    titleFont.setColor(new BaseColor(pdfDataExportOptions.getTitleColor().getRGB()));

    rowHeaderFont = new Font(pdfDataExportOptions.getFont());
    rowHeaderFont.setStyle(Font.BOLD);
    rowHeaderFont.setSize((float) pdfDataExportOptions.getHeaderFontSize());
    rowHeaderFont.setColor(new BaseColor(pdfDataExportOptions.getHeaderColor().getRGB()));
    rowHeaderBaseFont = rowHeaderFont.getCalculatedBaseFont(false);

    tableDataFont = pdfDataExportOptions.getFont();

    // Constructing progress bar.
    dumpProgressBar = new ProgressBar(exportedTable + " Dump");
    dumpProgressBar.setTaskLength(rowNumber);
    dumpProgressBar.pack();
    dumpProgressBar.center();
    dumpProgressBar.setVisible(true);

    // Create a Title if Optioned.
    title = pdfDataExportOptions.getTitle();

    if (!title.equals("")) {
        if (title.equals("EXPORTED TABLE"))
            title = exportedTable;

        titleCell = new PdfPCell(new Phrase(title, titleFont));
        titleCell.setBorder(0);
        titleCell.setPadding(10);
        titleCell.setColspan(summaryListTable.getColumnCount());
        titleCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        pdfTable.addCell(titleCell);
        pdfTable.setHeaderRows(2);
    } else
        pdfTable.setHeaderRows(1);

    // Create Row Header.
    for (int i = 0; i < columnCount; i++) {
        currentTableFieldName = summaryListTable.getColumnName(i);
        rowHeaderCell = new PdfPCell(new Phrase(currentTableFieldName, rowHeaderFont));
        rowHeaderCell.setBorderWidth(pdfDataExportOptions.getHeaderBorderSize());
        rowHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        rowHeaderCell.setBorderColor(new BaseColor(pdfDataExportOptions.getHeaderBorderColor().getRGB()));
        pdfTable.addCell(rowHeaderCell);
        columnWidths[i] = Math.min(50000,
                Math.max(columnWidths[i], rowHeaderBaseFont.getWidth(currentTableFieldName + " ")));
        if (tableColumnTypeNameHashMap != null)
            summaryListTableNameTypes.put(Integer.toString(i),
                    tableColumnTypeNameHashMap.get(currentTableFieldName));
        else
            summaryListTableNameTypes.put(Integer.toString(i), "String");
    }

    // Create the Body of Data.
    int i = 0;
    while ((i < rowNumber) && !dumpProgressBar.isCanceled()) {
        dumpProgressBar.setCurrentValue(i);

        // Collecting rows of data & formatting date & timestamps
        // as needed according to the Export Properties.

        if (summaryListTable.getValueAt(i, 0) != null) {
            for (int j = 0; j < summaryListTable.getColumnCount(); j++) {
                currentString = summaryListTable.getValueAt(i, j) + "";
                currentString = currentString.replaceAll("\n", "");
                currentString = currentString.replaceAll("\r", "");
                currentType = summaryListTableNameTypes.get(Integer.toString(j));

                // Format Date & Timestamp Fields as Needed.

                if ((currentType != null) && (currentType.equals("DATE") || currentType.equals("DATETIME")
                        || currentType.indexOf("TIMESTAMP") != -1)) {
                    if (!currentString.toLowerCase(Locale.ENGLISH).equals("null")) {
                        int firstSpace;
                        String time;

                        // Dates fall through DateTime and Timestamps try
                        // to get the time separated before formatting
                        // the date.

                        if (currentString.indexOf(" ") != -1) {
                            firstSpace = currentString.indexOf(" ");
                            time = currentString.substring(firstSpace);
                            currentString = currentString.substring(0, firstSpace);
                        } else
                            time = "";

                        currentString = Utils.convertViewDateString_To_DBDateString(currentString,
                                DBTablesPanel.getGeneralDBProperties().getViewDateFormat());
                        currentString = Utils.convertDBDateString_To_ViewDateString(currentString,
                                pdfDataExportOptions.getPDFDateFormat()) + time;
                    }
                }
                bodyCell = new PdfPCell(new Phrase(currentString, tableDataFont));
                bodyCell.setPaddingBottom(4);

                if (currentType != null) {
                    // Set Numeric Fields Alignment.
                    if (currentType.indexOf("BIT") != -1 || currentType.indexOf("BOOL") != -1
                            || currentType.indexOf("NUM") != -1 || currentType.indexOf("INT") != -1
                            || currentType.indexOf("FLOAT") != -1 || currentType.indexOf("DOUBLE") != -1
                            || currentType.equals("REAL") || currentType.equals("DECIMAL")
                            || currentType.indexOf("COUNTER") != -1 || currentType.equals("BYTE")
                            || currentType.equals("CURRENCY")) {
                        bodyCell.setHorizontalAlignment(pdfDataExportOptions.getNumberAlignment());
                        bodyCell.setPaddingRight(4);
                    }
                    // Set Date/Time Field Alignment.
                    if (currentType.indexOf("DATE") != -1 || currentType.indexOf("TIME") != -1
                            || currentType.indexOf("YEAR") != -1)
                        bodyCell.setHorizontalAlignment(pdfDataExportOptions.getDateAlignment());
                }

                pdfTable.addCell(bodyCell);
                columnWidths[j] = Math.min(50000,
                        Math.max(columnWidths[j], BASE_FONT.getWidth(currentString + " ")));
            }
        }
        i++;
    }
    dumpProgressBar.dispose();

    // Check to see if any data was in the summary
    // table to even be saved.

    if (pdfTable.size() <= pdfTable.getHeaderRows())
        return;

    // Create a document of the PDF formatted data
    // to be saved to the given output file.

    try {
        // Sizing & Layout
        totalWidth = 0;
        for (int width : columnWidths)
            totalWidth += width;

        if (pdfDataExportOptions.getPageLayout() == PDFExportPreferencesPanel.LAYOUT_PORTRAIT)
            pageSize = PageSize.A4;
        else {
            pageSize = PageSize.A4.rotate();
            pageSize.setRight(pageSize.getRight() * Math.max(1f, totalWidth / 53000f));
            pageSize.setTop(pageSize.getTop() * Math.max(1f, totalWidth / 53000f));
        }

        pdfTable.setWidths(columnWidths);

        // Document
        pdfDocument = new Document(pageSize);
        byteArrayOutputStream = new ByteArrayOutputStream();
        pdfWriter = PdfWriter.getInstance(pdfDocument, byteArrayOutputStream);
        pdfDocument.open();
        pdfTemplate = pdfWriter.getDirectContent().createTemplate(100, 100);
        pdfTemplate.setBoundingBox(new com.itextpdf.text.Rectangle(-20, -20, 100, 100));
        pdfWriter.setPageEvent(this);
        pdfDocument.add(pdfTable);
        pdfDocument.close();

        // Outputting
        WriteDataFile.mainWriteDataString(fileName, byteArrayOutputStream.toByteArray(), false);

    } catch (DocumentException de) {
        if (Ajqvue.getDebug()) {
            System.out.println("Failed to Create Document Needed to Output Data. \n" + de.toString());
        }
    }
}

From source file:com.dandymadeproductions.myjsqlview.io.PDFDataTableDumpThread.java

License:Open Source License

public void run() {
    // Class Method Instances
    String title;//from  w w  w .j a  va  2s  . co  m
    PdfPTable pdfTable;
    PdfPCell titleCell, rowHeaderCell, bodyCell;
    Document pdfDocument;
    PdfWriter pdfWriter;
    ByteArrayOutputStream byteArrayOutputStream;

    int columnCount, rowNumber;
    int[] columnWidths;
    int totalWidth;
    Rectangle pageSize;

    MyJSQLView_ProgressBar dumpProgressBar;
    HashMap<String, String> summaryListTableNameTypes;
    String currentTableFieldName;
    String currentType, currentString;

    // Setup
    columnCount = summaryListTable.getColumnCount();
    rowNumber = summaryListTable.getRowCount();
    columnWidths = new int[columnCount];

    pdfTable = new PdfPTable(columnCount);
    pdfTable.setWidthPercentage(100);
    pdfTable.getDefaultCell().setPaddingBottom(4);
    pdfTable.getDefaultCell().setBorderWidth(1);

    summaryListTableNameTypes = new HashMap<String, String>();
    pdfDataExportOptions = DBTablesPanel.getDataExportProperties();

    titleFont = new Font(pdfDataExportOptions.getFont());
    titleFont.setStyle(Font.BOLD);
    titleFont.setSize((float) pdfDataExportOptions.getTitleFontSize());
    titleFont.setColor(new BaseColor(pdfDataExportOptions.getTitleColor().getRGB()));

    rowHeaderFont = new Font(pdfDataExportOptions.getFont());
    rowHeaderFont.setStyle(Font.BOLD);
    rowHeaderFont.setSize((float) pdfDataExportOptions.getHeaderFontSize());
    rowHeaderFont.setColor(new BaseColor(pdfDataExportOptions.getHeaderColor().getRGB()));
    rowHeaderBaseFont = rowHeaderFont.getCalculatedBaseFont(false);

    tableDataFont = pdfDataExportOptions.getFont();

    // Constructing progress bar.
    rowNumber = summaryListTable.getRowCount();
    dumpProgressBar = new MyJSQLView_ProgressBar(exportedTable + " Dump");
    dumpProgressBar.setTaskLength(rowNumber);
    dumpProgressBar.pack();
    dumpProgressBar.center();
    dumpProgressBar.setVisible(true);

    // Create a Title if Optioned.
    title = pdfDataExportOptions.getTitle();

    if (!title.equals("")) {
        if (title.equals("EXPORTED TABLE"))
            title = exportedTable;

        titleCell = new PdfPCell(new Phrase(title, titleFont));
        titleCell.setBorder(0);
        titleCell.setPadding(10);
        titleCell.setColspan(summaryListTable.getColumnCount());
        titleCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        pdfTable.addCell(titleCell);
        pdfTable.setHeaderRows(2);
    } else
        pdfTable.setHeaderRows(1);

    // Create Row Header.
    for (int i = 0; i < columnCount; i++) {
        currentTableFieldName = summaryListTable.getColumnName(i);
        rowHeaderCell = new PdfPCell(new Phrase(currentTableFieldName, rowHeaderFont));
        rowHeaderCell.setBorderWidth(pdfDataExportOptions.getHeaderBorderSize());
        rowHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        rowHeaderCell.setBorderColor(new BaseColor(pdfDataExportOptions.getHeaderBorderColor().getRGB()));
        pdfTable.addCell(rowHeaderCell);
        columnWidths[i] = Math.min(50000,
                Math.max(columnWidths[i], rowHeaderBaseFont.getWidth(currentTableFieldName + " ")));
        if (tableColumnTypeHashMap != null)
            summaryListTableNameTypes.put(Integer.toString(i),
                    tableColumnTypeHashMap.get(currentTableFieldName));
        else
            summaryListTableNameTypes.put(Integer.toString(i), "String");
    }

    // Create the Body of Data.
    int i = 0;
    while ((i < rowNumber) && !dumpProgressBar.isCanceled()) {
        dumpProgressBar.setCurrentValue(i);

        // Collecting rows of data & formatting date & timestamps
        // as needed according to the Export Properties.

        if (summaryListTable.getValueAt(i, 0) != null) {
            for (int j = 0; j < summaryListTable.getColumnCount(); j++) {
                currentString = summaryListTable.getValueAt(i, j) + "";
                currentString = currentString.replaceAll("\n", "");
                currentString = currentString.replaceAll("\r", "");
                currentType = summaryListTableNameTypes.get(Integer.toString(j));

                // Format Date & Timestamp Fields as Needed.

                if ((currentType != null) && (currentType.equals("DATE") || currentType.equals("DATETIME")
                        || currentType.indexOf("TIMESTAMP") != -1)) {
                    if (!currentString.toLowerCase().equals("null")) {
                        int firstSpace;
                        String time;

                        // Dates fall through DateTime and Timestamps try
                        // to get the time separated before formatting
                        // the date.

                        if (currentString.indexOf(" ") != -1) {
                            firstSpace = currentString.indexOf(" ");
                            time = currentString.substring(firstSpace);
                            currentString = currentString.substring(0, firstSpace);
                        } else
                            time = "";

                        currentString = MyJSQLView_Utils.convertViewDateString_To_DBDateString(currentString,
                                DBTablesPanel.getGeneralDBProperties().getViewDateFormat());
                        currentString = MyJSQLView_Utils.convertDBDateString_To_ViewDateString(currentString,
                                pdfDataExportOptions.getPDFDateFormat()) + time;
                    }
                }
                bodyCell = new PdfPCell(new Phrase(currentString, tableDataFont));
                bodyCell.setPaddingBottom(4);

                if (currentType != null) {
                    // Set Numeric Fields Alignment.
                    if (currentType.indexOf("BIT") != -1 || currentType.indexOf("BOOL") != -1
                            || currentType.indexOf("NUM") != -1 || currentType.indexOf("INT") != -1
                            || currentType.indexOf("FLOAT") != -1 || currentType.indexOf("DOUBLE") != -1
                            || currentType.equals("REAL") || currentType.equals("DECIMAL")
                            || currentType.indexOf("COUNTER") != -1 || currentType.equals("BYTE")
                            || currentType.equals("CURRENCY")) {
                        bodyCell.setHorizontalAlignment(pdfDataExportOptions.getNumberAlignment());
                        bodyCell.setPaddingRight(4);
                    }
                    // Set Date/Time Field Alignment.
                    if (currentType.indexOf("DATE") != -1 || currentType.indexOf("TIME") != -1
                            || currentType.indexOf("YEAR") != -1)
                        bodyCell.setHorizontalAlignment(pdfDataExportOptions.getDateAlignment());
                }

                pdfTable.addCell(bodyCell);
                columnWidths[j] = Math.min(50000,
                        Math.max(columnWidths[j], BASE_FONT.getWidth(currentString + " ")));
            }
        }
        i++;
    }
    dumpProgressBar.dispose();

    // Check to see if any data was in the summary
    // table to even be saved.

    if (pdfTable.size() <= pdfTable.getHeaderRows())
        return;

    // Create a document of the PDF formatted data
    // to be saved to the given output file.

    try {
        // Sizing & Layout
        totalWidth = 0;
        for (int width : columnWidths)
            totalWidth += width;

        if (pdfDataExportOptions.getPageLayout() == PDFExportPreferencesPanel.LAYOUT_PORTRAIT)
            pageSize = PageSize.A4;
        else {
            pageSize = PageSize.A4.rotate();
            pageSize.setRight(pageSize.getRight() * Math.max(1f, totalWidth / 53000f));
            pageSize.setTop(pageSize.getTop() * Math.max(1f, totalWidth / 53000f));
        }

        pdfTable.setWidths(columnWidths);

        // Document
        pdfDocument = new Document(pageSize);
        byteArrayOutputStream = new ByteArrayOutputStream();
        pdfWriter = PdfWriter.getInstance(pdfDocument, byteArrayOutputStream);
        pdfDocument.open();
        pdfTemplate = pdfWriter.getDirectContent().createTemplate(100, 100);
        pdfTemplate.setBoundingBox(new com.itextpdf.text.Rectangle(-20, -20, 100, 100));
        pdfWriter.setPageEvent(this);
        pdfDocument.add(pdfTable);
        pdfDocument.close();

        // Outputting
        WriteDataFile.mainWriteDataString(fileName, byteArrayOutputStream.toByteArray(), false);

    } catch (DocumentException de) {
        if (MyJSQLView.getDebug()) {
            System.out.println("Failed to Create Document Needed to Output Data. \n" + de.toString());
        }
    }
}

From source file:com.deadormi.servlet.CreaPdfServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w w w  .  j a v a 2 s.  c  o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String url = request.getQueryString();
    Integer gruppo_id = Integer.parseInt(url.substring(url.indexOf("=") + 1, url.length()));

    List<Utente> iscritti = null;
    List<Post> posts = null;
    Gruppo gruppo = null;
    Utente utente = null;
    String imageUrl = null;
    String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();

    try {
        iscritti = UtenteController.getUserByGroupId(request, gruppo_id);
        gruppo = GruppoController.getGruppoById(request, gruppo_id);
    } catch (SQLException ex) {
        log.error(ex);
    }

    // step 1: creation of a document-object
    Document document = new Document();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();

        String incipit = "Report del " + CurrentDate.getCurrentDate() + "\n";
        Paragraph pIncipit = new Paragraph(incipit,
                FontFactory.getFont(FontFactory.HELVETICA, 14, BaseColor.BLACK));
        pIncipit.setAlignment(Element.ALIGN_CENTER);
        pIncipit.setSpacingAfter(10);
        document.add(pIncipit);

        String title = "Gruppo " + gruppo.getNome();
        Paragraph pTitle = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 18, BaseColor.BLUE));
        pTitle.setAlignment(Element.ALIGN_CENTER);
        pTitle.setSpacingAfter(40);
        document.add(pTitle);

        PdfPCell labelNome = new PdfPCell(new Paragraph("Nome utente"));
        PdfPCell labelNumPost = new PdfPCell(new Paragraph("Num. post"));
        PdfPCell labelData = new PdfPCell(new Paragraph("Data ultimo post"));
        labelNome.setBorder(Rectangle.NO_BORDER);
        labelNumPost.setBorder(Rectangle.NO_BORDER);
        labelData.setBorder(Rectangle.NO_BORDER);

        for (int i = 0; i < iscritti.size(); i++) {
            utente = iscritti.get(i);
            try {
                posts = PostController.getPostByGruppoIdAndUserId(request, gruppo_id, utente.getId_utente());
            } catch (SQLException ex) {
                Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (utente.getNome_avatar() != null) {
                imageUrl = baseUrl + request.getContextPath() + AVATAR_RESOURCE_PATH + "/"
                        + utente.getId_utente() + "_" + utente.getNome_avatar();
                ;
            } else {
                imageUrl = baseUrl + request.getContextPath() + "/res/images/user_avatar.png";
            }
            Image image = Image.getInstance(new URL(imageUrl));
            image.scaleToFit(50, 50);

            PdfPTable table = new PdfPTable(3);

            PdfPCell cellAvatar = new PdfPCell(image);
            cellAvatar.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellAvatar.setBorder(Rectangle.NO_BORDER);
            cellAvatar.setRowspan(3);

            PdfPCell cellNome = new PdfPCell(new Paragraph(utente.getUsername() + ""));
            cellNome.setBorder(Rectangle.NO_BORDER);

            PdfPCell cellNumPost = new PdfPCell(new Paragraph(posts.size() + ""));
            cellNumPost.setBorder(Rectangle.NO_BORDER);

            //L'ultimo  sempre il piu recente siccome la query  ORDER BY data_creazione
            PdfPCell cellData;
            if (posts.size() != 0) {
                cellData = new PdfPCell(new Paragraph(posts.get(posts.size() - 1).getData_creazione()));
            } else {
                cellData = new PdfPCell(new Paragraph("N/A"));

            }
            cellData.setBorder(Rectangle.NO_BORDER);

            PdfPCell cellVoidBottom = new PdfPCell(new Paragraph(" "));
            cellVoidBottom.setBorder(Rectangle.BOTTOM);
            cellVoidBottom.setPaddingBottom(10);
            cellVoidBottom.setColspan(3);

            PdfPCell cellVoidTop = new PdfPCell(new Paragraph(" "));
            cellVoidTop.setBorder(Rectangle.NO_BORDER);
            cellVoidTop.setPaddingTop(10);
            cellVoidTop.setColspan(3);

            table.addCell(cellVoidTop);
            table.addCell(cellAvatar);
            table.addCell(labelNome);
            table.addCell(cellNome);
            table.addCell(labelNumPost);
            table.addCell(cellNumPost);
            table.addCell(labelData);
            table.addCell(cellData);
            table.addCell(cellVoidBottom);

            document.add(table);

        }

        document.close();
        response.setContentType("application/pdf");
        response.addHeader("Content-Disposition", "inline; filename=ahahah.pdf");
        OutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
    } catch (DocumentException ex) {
        Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.debashubham.dumpy.ChainageCalcActivity.java

private void createTable(Section subCatPart) throws DocumentException {
    PdfPTable entry_table = new PdfPTable(10);
    entry_table.setWidthPercentage(100);
    //        entry_table.setWidths(new float[]{0.25f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,1.0f});
    PdfPCell id = new PdfPCell(new Phrase("Station Point"));
    id.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell left_row = new PdfPCell(new Phrase("CH. Left(m)"));
    left_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell center_row = new PdfPCell(new Phrase("CH. Center(m)"));
    center_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell right_row = new PdfPCell(new Phrase("CH. Right(m)"));
    right_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell bs = new PdfPCell(new Phrase("BS(m)"));
    bs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell is = new PdfPCell(new Phrase("IS(m)"));
    is.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell fs = new PdfPCell(new Phrase("FS(m)"));
    fs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell hi = new PdfPCell(new Phrase("HI(m)"));
    hi.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell rl = new PdfPCell(new Phrase("RL(m)"));
    rl.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell remarks = new PdfPCell(new Phrase("REMARKS"));
    remarks.setHorizontalAlignment(Element.ALIGN_CENTER);
    entry_table.addCell(id);
    entry_table.addCell(left_row);//from   w w  w. j av  a2  s  . c  o m
    entry_table.addCell(center_row);
    entry_table.addCell(right_row);
    entry_table.addCell(bs);
    entry_table.addCell(is);
    entry_table.addCell(fs);
    entry_table.addCell(hi);
    entry_table.addCell(rl);
    entry_table.addCell(remarks);
    entry_table.setHeaderRows(1);
    int largest = rl_list.size();

    Log.e("Total RL:", String.valueOf(largest));
    double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0;

    for (int i = 1; i <= largest; i++) {

        entry_table.addCell(String.valueOf(i));

        if (i == 1)
            first_rl = rl_list.get(i);
        if (i == largest)
            last_rl = rl_list.get(i);

        if (left.containsKey(i)) {
            entry_table.addCell(String.valueOf(left.get(i)));
            entry_table.addCell("");
            entry_table.addCell("");
        } else if (center.containsKey(i)) {
            entry_table.addCell("");
            entry_table.addCell(String.valueOf(center.get(i)));
            entry_table.addCell("");
        } else if (right.containsKey(i)) {
            entry_table.addCell("");
            entry_table.addCell("");
            entry_table.addCell(String.valueOf(right.get(i)));
        } else {
            entry_table.addCell("");
            entry_table.addCell("");
            entry_table.addCell("");
        }

        if (bs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(bs_list.get(i)));
            total_bs += bs_list.get(i);
            Log.e("TABLE:", "BS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "BS not entered");
        }
        if (is_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(is_list.get(i)));
            Log.e("TABLE:", "IS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "IS not entered");
        }
        if (fs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(fs_list.get(i)));
            total_fs += fs_list.get(i);
            Log.e("TABLE:", "FS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "FS not entered");
        }
        if (hi_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(hi_list.get(i)));
            Log.e("TABLE:", "HI");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "HI not entered");
        }
        if (rl_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(rl_list.get(i)));
            Log.e("TABLE:", "RL");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "RL not entered");
        }
        if (remarks_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(remarks_list.get(i)));
            Log.e("TABLE:", "REMARKS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "REMARKS not entered");
        }
    }
    subCatPart.add(entry_table);
    Log.e("Total BS:", String.valueOf(total_bs));
    Log.e("Total FS:", String.valueOf(total_fs));
    Log.e("First RL:", String.valueOf(first_rl));
    Log.e("Last RL:", String.valueOf(last_rl));
    Paragraph check_para = new Paragraph("Arithmetic Check:", subFont);
    addEmptyLine(check_para, 2);
    check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL");
    addEmptyLine(check_para, 1);
    double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0;
    double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0;
    boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false;
    check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff));
    addEmptyLine(check_para, 1);
    if (checktrue) {
        check_para.setSpacingBefore(20);
        check_para.add("OK");
    } else {
        check_para.setSpacingBefore(20);
        check_para.add("Check Fail!");
    }
    addEmptyLine(check_para, 1);
    check_para.add("_______________________________________________________");
    subCatPart.add(check_para);
    Paragraph legend_para = new Paragraph("LEGEND:", subFont);
    addEmptyLine(legend_para, 1);
    legend_para.add("BS : Back Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("IS : Intermediate Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("FS : Fore Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("HI : Height of Instrument");
    addEmptyLine(legend_para, 1);
    legend_para.add("RL : Reduced Level");
    addEmptyLine(legend_para, 1);
    legend_para.add("CH. : Chainage");
    subCatPart.add(legend_para);
}

From source file:com.debashubham.dumpy.SimpleCalcActivity.java

private void createTable(Section subCatPart) throws BadElementException {
    PdfPTable entry_table = new PdfPTable(7);
    entry_table.setWidthPercentage(100);
    PdfPCell id = new PdfPCell(new Phrase("Station Point"));
    id.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell bs = new PdfPCell(new Phrase("BS"));
    bs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell is = new PdfPCell(new Phrase("IS"));
    is.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell fs = new PdfPCell(new Phrase("FS"));
    fs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell hi = new PdfPCell(new Phrase("HI"));
    hi.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell rl = new PdfPCell(new Phrase("RL"));
    rl.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell remarks = new PdfPCell(new Phrase("REMARKS"));
    remarks.setHorizontalAlignment(Element.ALIGN_CENTER);
    entry_table.addCell(id);
    entry_table.addCell(bs);/*from w  ww  .jav  a  2  s .  c o m*/
    entry_table.addCell(is);
    entry_table.addCell(fs);
    entry_table.addCell(hi);
    entry_table.addCell(rl);
    entry_table.addCell(remarks);
    entry_table.setHeaderRows(1);
    int largest = rl_list.size();

    Log.e("Total RL:", String.valueOf(largest));
    double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0;

    for (int i = 1; i <= largest; i++) {

        entry_table.addCell(String.valueOf(i));

        if (i == 1)
            first_rl = rl_list.get(i);
        if (i == largest)
            last_rl = rl_list.get(i);

        if (bs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(bs_list.get(i)));
            total_bs += bs_list.get(i);
            Log.e("TABLE:", "BS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "BS not entered");
        }
        if (is_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(is_list.get(i)));
            Log.e("TABLE:", "IS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "IS not entered");
        }
        if (fs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(fs_list.get(i)));
            total_fs += fs_list.get(i);
            Log.e("TABLE:", "FS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "FS not entered");
        }
        if (hi_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(hi_list.get(i)));
            Log.e("TABLE:", "HI");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "HI not entered");
        }
        if (rl_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(rl_list.get(i)));
            Log.e("TABLE:", "RL");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "RL not entered");
        }
        if (remarks_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(remarks_list.get(i)));
            Log.e("TABLE:", "REMARKS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "REMARKS not entered");
        }
    }
    subCatPart.add(entry_table);
    Log.e("Total BS:", String.valueOf(total_bs));
    Log.e("Total FS:", String.valueOf(total_fs));
    Log.e("First RL:", String.valueOf(first_rl));
    Log.e("Last RL:", String.valueOf(last_rl));
    Paragraph check_para = new Paragraph("Arithmetic Check:", subFont);
    addEmptyLine(check_para, 2);
    check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL");
    addEmptyLine(check_para, 1);
    double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0;
    double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0;
    boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false;
    check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff));
    addEmptyLine(check_para, 1);
    if (checktrue) {
        check_para.setSpacingBefore(20);
        check_para.add("OK");
    } else {
        check_para.setSpacingBefore(20);
        check_para.add("Check Fail!");
    }
    addEmptyLine(check_para, 1);
    check_para.add("_______________________________________________________");
    subCatPart.add(check_para);
    Paragraph legend_para = new Paragraph("LEGEND:", subFont);
    addEmptyLine(legend_para, 2);
    legend_para.add("BS : Back Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("IS : Intermediate Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("FS : Fore Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("HI : Height of Instrument");
    addEmptyLine(legend_para, 1);
    legend_para.add("RL : Reduced Level");
    subCatPart.add(legend_para);
}

From source file:com.devox.GUI.PDF.CrearReporteApto.java

@Override
public PdfPTable configurarInformacion() {
    PdfPTable table = new PdfPTable(2);
    PdfPCell cell;/* w w  w  .j av  a2  s .c  o  m*/
    cell = new PdfPCell(getPhraseFromChunks("FACTURA ", factura));
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);
    cell = new PdfPCell(getPhraseFromChunks("FECHA FACTURA", ""));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setRowspan(2);
    table.addCell(cell);
    cell = new PdfPCell(getPhraseFromChunks("FOLIO CLIENTE ", folioCliente));
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);
    cell = new PdfPCell(getPhraseFromChunks("CLIENTE ", clienteSucursal));
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);
    cell = new PdfPCell(getPhraseFromChunks("MOTIVO ", motivo));
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);
    table.setTotalWidth(400);
    return table;
}

From source file:com.devox.GUI.PDF.CrearReporteApto.java

@Override
public PdfPTable crearTabla() {
    PdfPTable table = new PdfPTable(8);
    //new float[]{2.4f, 3f, 1.25f, 1.2f, 1f, 1.15f, 1.1f, 1.55f}
    PdfPCell cell;//from ww w.j  av  a 2s.co  m
    cell = new PdfPCell(new Phrase("CDIGO", FUENTE_CABECERA_TABLA_CHICA));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setFixedHeight(20f);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("DESCRIPCIN", FUENTE_CABECERA_TABLA_CHICA));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("LOTE", FUENTE_CABECERA_TABLA_CHICA));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("FECHA DE CADUCIDAD", FUENTE_CABECERA_TABLA_CHICA));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("CANTIDAD", FUENTE_CABECERA_TABLA_CHICA));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("DICTAMEN", FUENTE_CABECERA_TABLA_CHICA));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(AMARILLO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("PRECIO", FUENTE_CABECERA_TABLA_CHICA));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(AMARILLO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("OBSERVACIONES", FUENTE_CABECERA_TABLA_CHICA));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(AMARILLO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);
    try {
        table.setWidths(new float[] { 2.4f, 3f, 1.25f, 1.2f, 1f, 1.15f, 1.1f, 1.55f });
        table.setWidthPercentage(100);

    } catch (DocumentException ex) {
        Log.print(ex);
    }
    return table;
}

From source file:com.devox.GUI.PDF.CrearReporteApto.java

@Override
public void agregarProductos(PdfPTable table) {
    int rows = datos.length;
    Log.print("rows: " + rows);
    int total = 0;
    float precio = 0;
    for (int i = 0; i < rows; i++) {
        // Cdigo/*from w w w  . j  a  va2  s  . co m*/
        PdfPCell cell = new PdfPCell(new Phrase(datos[i][0].toString(), FUENTE_TABLA));
        cell.setFixedHeight(21f);
        table.addCell(cell);
        // Descripcin
        table.addCell(new Phrase(datos[i][1].toString(), FUENTE_TABLA));
        // Lote
        table.addCell(new Phrase(datos[i][2].toString(), FUENTE_TABLA));
        // Fecha de caducidad
        table.addCell(new Phrase("  "));
        // Cantidad
        int c = ((Integer) datos[i][3]);
        total += c;
        table.addCell(new Phrase(datos[i][3].toString(), FUENTE_TABLA));
        // Dictamen
        table.addCell(new Phrase("  "));
        // Precio
        float p = new Float(datos[i][4].toString());
        precio += (c * p);
        table.addCell(new Phrase(datos[i][4].toString(), FUENTE_TABLA));
        // Observaciones
        table.addCell(new Phrase("  "));

    }
    table.addCell(new Phrase("  ", FUENTE_BASE_TABLA));
    table.addCell(new Phrase("  ", FUENTE_BASE_TABLA));
    table.addCell(new Phrase("  ", FUENTE_BASE_TABLA));
    table.addCell(new Phrase("SUMA ", FUENTE_BASE_TABLA));
    table.addCell(new Phrase("" + total, FUENTE_BASE_TABLA));
    table.addCell(new Phrase("  ", FUENTE_BASE_TABLA));
    table.addCell(new Phrase("$ " + String.format("%.2f", precio), FUENTE_BASE_TABLA));
    table.addCell(new Phrase("  ", FUENTE_BASE_TABLA));
}