I created a PDF file with the data from an Excel file. I am not sure what was happened, but when I tried to remove one PdfPage and insert it somewhere else, it showed the warning message "The removing page has already been flushed".
The used code is quite simple:
PdfDocument pdf = ...;
....
PdfPage page = pdf.removePage(10);
pdf.addPage(1, page);
But I got warning and errors:
[main] WARN com.itextpdf.kernel.pdf.PdfPage - The removing page has already been flushed. Exception in thread "main" com.itextpdf.kernel.PdfException:flushed.page.cannot.be.added.or.inserted at com.itextpdf.kernel.pdf.PdfDocument.checkAndAddPage(PdfDocument.java:1473) at com.itextpdf.kernel.pdf.PdfDocument.addPage(PdfDocument.java:437)
To be honest, I did have tried the above code with some other PDF files, it works to remove and to insert pages. What could be the possible reasons with my PDF file?
Complete code used in my application:
PdfWriter writer;
PdfDocument pdfDocument;
Document document;
try {
writer = new PdfWriter(FileConfigurator.getAbsoluteResultFilePath(),
new WriterProperties().addXmpMetadata().setPdfVersion(PdfVersion.PDF_1_7));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//Initialize PDF document
pdfDocument = new PdfDocument(writer);
// Initialize document
document = new Document(pdfDocument);