【发布时间】:2013-08-08 00:36:14
【问题描述】:
我想使用大型不露面的 JAVA api 将 pdf 文件附加到特定位置的现有 PDF 文件中。谁能帮助我怎么做?
【问题讨论】:
-
您需要哪些信息?我的回答够吗?
-
如何将页面附加到特定位置。
标签: java jakarta-ee pdf-generation itext
我想使用大型不露面的 JAVA api 将 pdf 文件附加到特定位置的现有 PDF 文件中。谁能帮助我怎么做?
【问题讨论】:
标签: java jakarta-ee pdf-generation itext
您可以使用开源库iText。
这个例子展示了如何合并两个 PDF。
public class Merge
{
public static final String SOURCE_PDF = "a.pdf";
public static final String APPENDED_PDF = "b.pdf";
public static final String MERGED_RESULT = "c.pdf";
public static void main(String[] args) throws IOException, DocumentException, SQLException
{
PdfReader sourcePdf = new PdfReader(SOURCE_PDF);
PdfReader appendedPdf = new PdfReader(APPENDED_PDF);
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileOutputStream(MERGED_RESULT));
document.open();
for (PdfReader reader : Arrays.asList(sourcePdf, appendedPdf))
{
for (int page = 1; page <= reader.getNumberOfPages(); page++)
{
copy.addPage(copy.getImportedPage(reader, page));
}
copy.freeReader(reader);
reader.close();
}
document.close();
}
}
复制自here。
【讨论】: