是否可以使用iText7合并多个pdf [英] Is it possible to merger several pdfs using iText7

查看:386
本文介绍了是否可以使用iText7合并多个pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此问道道歉,但我在iText网站上看​​不到任何确定的内容。

Apologies for asking this, but I cannot see anything definitive on the iText website.

我有几个产品数据表。每个都是一个单独的文件。我想要做的是使用iText根据webform的答案生成摘要/推荐的一组操作,然后附加到所有相关的数据表。这样,我只需要在浏览器中打开一个新选项卡来打印所有信息,而不是为摘要打开一个,每个数据表需要一个。

I have several datasheets for products. Each is a separate file. What I want to do is to use iText to generate a summary / recommended set of actions, based on answers to a webform, and then append to that all the relevant datasheets. This way, I only need to open one new tab in the browser to print all information, rather than opening one for the summary, and one for each datasheet that is needed.

那么,是否可以使用iText以编程方式执行此操作?

So, is it possible to do this programmatically using iText?

推荐答案

是的,您可以使用iText 7合并PDF。例如查看 iText 7 Jump-Start教程示例 C06E04_88th_Oscar_Combine ,关键代码是:

Yes, you can merge PDFs using iText 7. E.g. look at the iText 7 Jump-Start tutorial sample C06E04_88th_Oscar_Combine, the pivotal code is:

PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
PdfMerger merger = new PdfMerger(pdf);

//Add pages from the first document
PdfDocument firstSourcePdf = new PdfDocument(new PdfReader(SRC1));
merger.merge(firstSourcePdf, 1, firstSourcePdf.getNumberOfPages());

//Add pages from the second pdf document
PdfDocument secondSourcePdf = new PdfDocument(new PdfReader(SRC2));
merger.merge(secondSourcePdf, 1, secondSourcePdf.getNumberOfPages());

firstSourcePdf.close();
secondSourcePdf.close();
pdf.close();

C06E04_88th_Oscar_Combine 方法 createPdf

根据您的使用情况,您可能希望使用 PdfDenseMerger 及其助手类 PageVerticalAnalyzer 而不是 PdfMerger 。它尝试将来自多个源页面的内容放到单个目标页面上,并对应于iText 5 这个答案的/mkl/testarea/itext5/merge/PdfVeryDenseMergeTool.java\"rel =nofollow noreferrer> PdfVeryDenseMergeTool 。由于PDF文件的性质,这仅适用于没有页眉,页脚和类似工件的PDF。

Depending on your use case, you might want to use the PdfDenseMerger with its helper class PageVerticalAnalyzer instead of the PdfMerger here. It attempts to put content from multiple source pages onto a single target page and corresponds to the iText 5 PdfVeryDenseMergeTool from this answer. Due to the nature of PDF files this only works for PDFs without headers, footers, and similar artifacts.

这篇关于是否可以使用iText7合并多个pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆