在iText中创建PDF图像 [英] Creating a PDF image in iText
问题描述
我正在尝试将我在文件系统上的图像作为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?
推荐答案
请下载< a href =http://manning.com/lowagie2/samplechapter6.pdf =nofollow noreferrer>我的书第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图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!