Java 在itext中添加表的单元格

Java 在itext中添加表的单元格,java,itext,Java,Itext,为什么包含段落p的单元格未添加到表中 package iText; import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Document; import com.itextpdf.text.*; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Font.FontFamily; import com.it

为什么包含段落p的单元格未添加到表中

package iText;

import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.*;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.FileOutputStream;

public class NewMain1 {
    public static void main(String[] args) {
        Document document = new Document();

        try {
            PdfWriter.getInstance(document,
                new FileOutputStream("C:\\Users\\om\\Desktop\\pdf\\2.pdf"));

            document.open();

            PdfPTable table = new PdfPTable(3); // 3 columns.
             Font font = new Font(FontFamily.HELVETICA, 22, Font.BOLD, BaseColor.WHITE);
        Paragraph p = new Paragraph("xyz", font);
        table.addCell("abc");    
        table.addCell(p);

            table.addCell("cef");
            table.addCell("ghi");
           // table.completeRow();
            PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1"));
            PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2"));
            PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3"));

            table.addCell(cell1);
            table.addCell(cell2);
            table.addCell(cell3);
cell1.setHorizontalAlignment(Element.ALIGN_LEFT);

            document.add(table);

            document.close();
        } catch(Exception e){

        }
    }
}

p、 我是这方面的新手。如果有人能告诉我如何通过itext生成pdf表单,那就太好了。提前感谢:)

您正在创建一种白色字体,并将其绘制在通常显示为白色的画布上。它就在那里,你就是看不见。尝试将颜色更改为其他颜色,如
BaseColor.BLACK

编辑

为了回答注释中的问题,构造函数的一个重载采用一个矩形,该矩形定义了页面的默认大小。iText有一个名为的助手类,它定义了许多常用页面,但您可以自由使用从
3x3
14400x14400
的任何维度。例如,您可以说
newdocument(PageSize.LETTER)
newdocument(newrectanglereadonly(612702))


一旦你知道了这一点,你就得到了你的最大
x
y
,除非你做了一些非常奇怪的事情,否则你的最小
x
y
都是零。使用PDF时,左下角是原点,因此
0 x 0

或者试试谷歌。@Jens我看过这些例子,但我无法找出我的错误。thanx:)嗯,你能告诉我一件事吗。。如果我要画画布或矩形,或将图像或任何东西放置在特定的x和y坐标上,那么我如何知道这些坐标?