Please read the official documentation for iText 7, more specifically Chapter 6: Reusing existing PDF documents
In PDF, there's the concept of Form XObjects. A Form XObject is a piece of PDF content that is stored outside the content stream of a page, hence XObject which stands for eXternal Object. The use of the word Form in Form XObject could be confusing, because people might be thinking of a form as in a fillable form with fields. To avoid that confusing, we introduced the term PdfTemplate
in iText 5.
The class PdfImportedPage
you refer to was a subclass of PdfTemplate
: it was a piece of PDF syntax that could be reused in another page. Over the years, we noticed that people also got confused by the word PdfTemplate
.
In iText 7, we returned to the basics. When talking about a Form XObject, we use the class PdfFormXObject
. When talking about a page in a PDF file, we use the class PdfPage
.
This is how we get a PdfPage
from an existing document:
PdfDocument origPdf = new PdfDocument(new PdfReader(src));
PdfPage origPage = origPdf.getPage(1);
This is how we use that page in a new document:
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
PdfFormXObject pageCopy = origPage.copyAsFormXObject(pdf);
If you want to use that pageCopy
as an Image
, just create it like this:
Image image = new Image(pageCopy);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…