如何将双值添加到pdfpcell

时间:2015-03-26 19:38:20

标签: itext

        PdfPTable table = new PdfPTable(4); // 4 columns.

        PdfPCell cell1 = new PdfPCell(new Paragraph("Medicine Name"));
        PdfPCell cell2 = new PdfPCell(new Paragraph("Quantity"));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Price"));
        PdfPCell cell4 = new PdfPCell(new Paragraph("Total"));
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);

         while(rs.next())   // fetch & writing records in pdf files
        {
            quan=rs.getInt("quantity");
            pric=rs.getDouble("price");
            total=quan*pric;


            cell1 = new PdfPCell(new Paragraph(rs.getString("prodt_name")));
            cell2 = new PdfPCell(new Paragraph(quan));
            cell3 = new PdfPCell(new Paragraph(rs.getString("price")));
            cell4 = new PdfPCell(new Paragraph(total));
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);

        }

total是double值,Paragraph构造函数不接受double值。 那么如何在pdfpcell中插入double值

1 个答案:

答案 0 :(得分:1)

尝试String.valueOf

cell4 = new PdfPCell(new Paragraph(String.valueOf(total)));

String.valueOf(double)返回double参数的字符串表示形式。有关详细信息,请参阅official documentation