我正在尝试将我在文件系统上的图像作为pdf添加到我即时创建的pdf中。
I'm trying to add an image that I have on the filesystem as a pdf into a pdf that I'm creating on the fly.
我试图将使用Image类,但它似乎不适用于PDF(仅限JPEG,PNG或GIF)。如何从现有PDF创建元素,以便将其放入新PDF?
I tried to use the Image class, but it seems that it does not work with PDFs (only JPEG, PNG or GIF). How can I create an element from an existing PDF, so that I can place it in my new PDF?
推荐答案请下载我的书第6章并阅读了所有关于班级 PdfImportedPage 。
Please download chapter 6 of my book and read all about the class PdfImportedPage.
在最基本的示例中,您将创建一个 PdfReader 实例并导入页面进入 PdfWriter 实例,从这一点上你可以直接使用 PdfImportedPage 实例,或者包含在图像对象:
In the most basic example, you'd create a PdfReader instance and import the page into the PdfWriter instance, from which point on you can use the PdfImportedPage instance, either directly, or wrapped inside an Image object:
PdfReader reader = new PdfReader(existingPdf); PdfImportedPage page = writer.getImportedPage(reader, i); Image img = Image.getInstance(page); reader.close();更多推荐
在iText中创建PDF图像
发布评论