还有其他方法可以在ITEXT中绝对定位段落/短语,而无需使用writer对象和列文本类

问题描述

这是我正在使用的并且想要将 Powered by 放置在所需页面底部,而无需使用writer对象

i want the powered by to be displayed at the bottom of the pdf

package pdf_invoice;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.IOException;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class Article {
    
    public static final String RESULT
        = "E:\\InvoiceEdit.pdf";
   
    public static void main(String[] args)
        throws IOException,DocumentException 
    {
        new Article().createPdf(RESULT);
    }
    public void createPdf(String filename) throws DocumentException,FileNotFoundException
    {
        Document document = new Document(PageSize.A4);
        
        PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream(filename));
        
        document.open();
        document.add(new Paragraph("This is a new paragraph"));
        document.add(new Paragraph("This is a new paragraph"));
        document.add(new Paragraph("This is a new paragraph"));
        
        PdfPTable table=new PdfPTable(1);
        table.setTotalWidth(595f);
     
        PdfPCell cell=new PdfPCell(new Paragraph("Powered by"));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_BottOM);
        cell.setBorderWidth(0f);
        table.addCell(cell);
        document.add(table);
        document.close();
        
        System.out.println("generated");

    }
}

除了使用ColumnText和writer对象之外,我找不到创建表和定位的任何其他方式。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)