I'm switching some parts of my program from itext5 to itext 7. How can I import pages from others pdf's to a single one?
void merge(PdfDocument reader, PdfDocumentContentParser parser, int page) throws IOException {
PdfImportedPage importedPage = writer.getImportedPage(reader, page);
PdfContentByte directContent = writer.getDirectContent();
PageVerticalAnalyzer finder = parser.processContent(page, new PageVerticalAnalyzer());
if (finder.verticalFlips.size() < 2) {
return;
}
Rectangle pageSizeToImport = reader.GetPageSize(page);
int startFlip = finder.verticalFlips.size() - 1;
boolean first = true;
while (startFlip > 0) {
if (!first) {
newPage();
}
float freeSpace = yPosition - pageSize.getBottom();
int endFlip = startFlip + 1;
while ((endFlip > 1) && (finder.verticalFlips.get(startFlip) - finder.verticalFlips.get(endFlip - 2) < freeSpace)) {
endFlip -= 2;
}
if (endFlip < startFlip) {
float height = finder.verticalFlips.get(startFlip) - finder.verticalFlips.get(endFlip);
directContent.saveState();
directContent.rectangle(0, yPosition - height, pageSizeToImport.getWidth(), height);
directContent.clip();
directContent.newPath();
directContent.addTemplate(importedPage, 0, yPosition - (finder.verticalFlips.get(startFlip) - pageSizeToImport.getBottom()));
directContent.restoreState();
yPosition -= height + gap;
startFlip = endFlip - 1;
} else if (!first) {
throw new IllegalArgumentException(String.format("Page %s content sections too large.", page));
}
first = false;
}
}
I have been searching the web, reading the api's for itext7 and still can't turn this to make it work. Can't find any replacement for PdfImportedPage and PdfContentByte.
I have listed my code up, my main question is what to use in replacement for PdfImportedPage and PdfContentByte