Java 如何在itext中获得表格中的遗漏表格宽度

Java 如何在itext中获得表格中的遗漏表格宽度,java,itext,Java,Itext,我不熟悉iText。我想生成一个带有一个表的pdf。表由3个单元格组成(单元格1、单元格2、单元格3) Cell1和cell2数据是动态文本。在单元格1和单元格2填满后,我想在单元格3中填充一些文本,以留出空间,即表格中的剩余空间。但我无法知道cell3的剩余空间,因为cell1和Cell2是动态的。 我添加了固定高度。因此文本将自动截断。如果文本被截断,我想在单元格3中追加“…”? 嗨,rockey,欢迎来到stackoverflow。请确切地告诉我们你是如何陷入困境的,并可能向我们表明,在

我不熟悉iText。我想生成一个带有一个表的pdf。表由3个单元格组成(单元格1、单元格2、单元格3)

Cell1和cell2数据是动态文本。在单元格1和单元格2填满后,我想在单元格3中填充一些文本,以留出空间,即表格中的剩余空间。但我无法知道cell3的剩余空间,因为cell1和Cell2是动态的。 我添加了固定高度。因此文本将自动截断。如果文本被截断,我想在单元格3中追加“…”?


嗨,rockey,欢迎来到stackoverflow。请确切地告诉我们你是如何陷入困境的,并可能向我们表明,在你提出问题之前,你已经付出了努力。有人能帮忙吗?
private static void addData(Document document) throws Exception {

    PdfPTable targetCompanyDetails = new PdfPTable(1);
    targetCompanyDetails.setWidthPercentage(100);
    targetCompanyDetails.setWidths(new float[] { 100 });

    PdfPCell cell = new PdfPCell(
            new Paragraph("", PdfUtil.getFont(FontNames.AVENIRLTCOM_MEDIUM.getFontName(), 12, 1, BaseColor.WHITE)));
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);

    PdfPTable targetCompanyInfo = new PdfPTable(3);
    targetCompanyInfo.setWidthPercentage(100.5f);
    targetCompanyInfo.setWidths(new float[] { 69, 83, 63 });

    PdfPCell firstCell = new PdfPCell();
    //firstCell.setBorderWidth(0);
    firstCell.setFixedHeight(130f);
    Font companyNameFont = PdfUtil.getFont(FontNames.AVENIRLTCOM_85HEAVY.getFontName(), 10F, Font.NORMAL,
            new BaseColor(Color.decode(ColorCodes._336699.getColorCode()).getRGB()));
    Chunk ck = new Chunk("oracle oracle oracle oracle oracle oracle oracle oracle oracle oracle oracle oracle orac oracle oracle oracle orac", companyNameFont);
    Paragraph targetParagraph = new Paragraph();
    targetParagraph.setLeading(11.25f);
    targetParagraph.add(ck);
    PdfPCell targetCompanyName = new PdfPCell();
    targetCompanyName.addElement(targetParagraph);
    PdfPTable targetCompanyDescTable = new PdfPTable(1);
    targetCompanyDescTable.setWidthPercentage(100);
    targetCompanyDescTable.setWidths(new float[] { 100 });
    targetCompanyDescTable.addCell(targetCompanyName);

    firstCell.addElement(targetCompanyDescTable);

    Font sectorFont = PdfUtil.getFont(FontNames.AVENIRLTCOM_85HEAVY.getFontName(), 10F, Font.NORMAL,
            new BaseColor(Color.decode(ColorCodes._336699.getColorCode()).getRGB()));
    Chunk ck1 = new Chunk("oracle Akk soft ", sectorFont);
    Paragraph sectorParagraph = new Paragraph();
    sectorParagraph.setLeading(11.25f);
    sectorParagraph.add(ck1);
    PdfPCell sectorName = new PdfPCell();
    sectorName.addElement(sectorParagraph);
    PdfPTable sectorTable = new PdfPTable(1);
    sectorTable.setWidthPercentage(100);
    sectorTable.setWidths(new float[] { 100 });
    sectorTable.addCell(sectorName);
    firstCell.addElement(sectorTable);




    Font descFont = PdfUtil.getFont(FontNames.AVENIRLTCOM_85HEAVY.getFontName(), 10F, Font.NORMAL,
            new BaseColor(Color.decode(ColorCodes._336699.getColorCode()).getRGB()));
    String content = "As there are 11 entries in the collection this means that the for the final row of the table you only add one cell. Thus, that row is incomplete and won't be drawn.You should either track whether the number of entries you added is even (e.g. by counting or by switching a boolean value); if it is not even, you should finally add another, empty cell.(Or if you want to rely on iText not drawing incomplete rows, simply always add an empty cell after the loop.)";
    Chunk ck2 = new Chunk(content, descFont);
    Paragraph descParagraph = new Paragraph();
    descParagraph.setLeading(11.25f);
    descParagraph.add(ck2);
    PdfPCell descName = new PdfPCell();
    descName.addElement(descParagraph);
    PdfPTable descTable = new PdfPTable(1);
    descTable.setWidthPercentage(100);
    descTable.setWidths(new float[] { 100 });
    descTable.addCell(descName);
    firstCell.addElement(descTable);


    PdfPCell secondCell = new PdfPCell();
    //secondCell.setBorderWidth(0);
    secondCell.setFixedHeight(130f);

    PdfPCell thiredCell = new PdfPCell();
    //thiredCell.setBorderWidth(0);
    thiredCell.setFixedHeight(130f);


    targetCompanyInfo.addCell(firstCell);
    targetCompanyInfo.addCell(secondCell);
    targetCompanyInfo.addCell(thiredCell);
    cell.addElement(targetCompanyInfo);
    targetCompanyDetails.addCell(cell);
    document.add(targetCompanyDetails);

    float totalWidth = targetCompanyDescTable.getTotalWidth();
    System.out.println("totalWidth : " + totalWidth);
    System.out.println("totalWidth : " + targetCompanyDetails.getTotalWidth());
    System.out.println("totalWidth : " + targetCompanyInfo.getTotalWidth());
}