1

我正在为我的商店开发一个简单的发票生成软件。我正在尝试使用 iText 在 PDF 中打印最后的内容,但我无法使用与 ColumnText 一起使用的方法 setSimpleColumn 正常工作。我无法理解 llx,lly,urx,ury 的概念,但我正在尝试通过 hit n try 方法但无法获得任何结果这是我的代码

public class CreateInvoicePdf {
public static final String DEST="C:\\Users\\sanju\\Desktop\\resul.pdf";
public static void main(String args[]) throws FileNotFoundException, DocumentException
{
    File file = new File (DEST);
    file.getParentFile().mkdirs();
    new CreateInvoicePdf().createPdf(DEST);
}
public void createPdf(String dest) throws FileNotFoundException, DocumentException
{
    Document d = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream(dest));
    d.open();
    PdfContentByte can = writer.getDirectContent();
    Paragraph companyDetails = new Paragraph("CLIMAX EXCLUSIVE\nShop No. G1 G2 Mohan Bazar\nCentral Market Ashok Vihar\nNew Delhi-110052");
    Paragraph invoiceDetails = new Paragraph("Invoice No : 1234\nDate  :  10/05/2018\nPay : CASH");
    PdfPTable itemTable = new PdfPTable(9);
    itemTable.addCell("1");
    itemTable.addCell("Shirt");
    itemTable.addCell("1999");
    itemTable.addCell("1");
    itemTable.addCell("1999");
    itemTable.addCell("12");
    itemTable.addCell("1500");
    itemTable.addCell("250");
    itemTable.addCell("250");
    ColumnText ct = new ColumnText(can);
    ct.setSimpleColumn(100,200,300,400);
    ct.addElement(companyDetails);
    ct.go();
    ct.setSimpleColumn(400,200,600,700);
    ct.addElement(invoiceDetails);
    ct.go();
    ct.setSimpleColumn(100, 700, 500, 500);
    ct.addElement(itemTable);
    ct.go();
    d.close();
    writer.close();
}}

我得到的输出很奇怪。 截图输出PDF附件

我希望公司详细信息和地址在左上角 发票编号日期和详细信息在右上角 这些下面的发票项目表

4

0 回答 0