Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将页脚添加到现有PDF_Java_Pdf_Itext - Fatal编程技术网

Java 将页脚添加到现有PDF

Java 将页脚添加到现有PDF,java,pdf,itext,Java,Pdf,Itext,我正在尝试将页脚添加到现有的PDF中。我确实在PDF中添加了一个页脚 是否还要添加两行页脚?下面是我的代码: Document document = new Document(); PdfCopy copy = new PdfCopy(document, new FileOutputStream(new File("D:/TestDestination/Merge Output1.pdf"))); document.open(); PdfReader reader1 = new PdfRe

我正在尝试将页脚添加到现有的PDF中。我确实在PDF中添加了一个页脚

是否还要添加两行页脚?下面是我的代码:

Document document = new Document(); 

PdfCopy copy = new PdfCopy(document, new FileOutputStream(new File("D:/TestDestination/Merge Output1.pdf")));
document.open();

PdfReader reader1 = new PdfReader("D:/TestDestination/Merge Output.pdf");
int n1 = reader1.getNumberOfPages();

PdfImportedPage page;
PdfCopy.PageStamp stamp;
Font ffont = new Font(Font.FontFamily.UNDEFINED, 5, Font.ITALIC);

for (int i = 0; i < n1; ) {
    page = copy.getImportedPage(reader1, ++i);
    stamp = copy.createPageStamp(page);
    ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER,new Phrase(String.format("page %d of %d", i, n1)),297.5f, 28, 0);
    stamp.alterContents();
    copy.addPage(page);
}

document.close();
reader1.close();
Document Document=新文档();
PdfCopy copy=新的PdfCopy(文档,新文件输出流(新文件(“D:/TestDestination/Merge Output1.pdf”));
document.open();
PdfReader reader1=新的PdfReader(“D:/TestDestination/Merge Output.pdf”);
int n1=reader1.getNumberOfPages();
PDF导入页面;
PdfCopy.PageStamp;
Font ffont=新字体(Font.FontFamily.UNDEFINED,5,Font.斜体);
对于(int i=0;i
请转到并单击转到常见问题。选择

您当前使用的
ColumnText
方式允许您添加单行文本。您使用的是
ColumnText.showTextAligned(…)
,如我在回答问题时所述

您应该阅读以下问题的答案:

假设您没有访问官方网站的权限(否则您就不会发布您的问题),我将添加一个简短的代码片段:

ColumnText ct = new ColumnText(stamp.getUnderContent());
ct.setSimpleColumn(rectangle);
ct.addElement(new Paragraph("Whatever text needs to fit inside the rectangle"));
ct.go();
在此代码段中,
stamp
是您在代码中创建的对象。
rectangle
对象的类型为
rectangle
。其参数是要在其中渲染多行文本的矩形的左下角和右上角的坐标


警告:所有不符合
矩形的文本将被删除。可以通过先在模拟模式下添加文本来避免这种情况。如果文本合适,请将其添加为真实文本。如果不合适,请使用较小的字体或较大的矩形重新尝试。

我尝试了很多关于添加段落作为页眉或页脚的方法。这种语法效果很好!!!。谢谢你,布鲁诺!!!