The removing page has already been flushed

风流意气都作罢 提交于 2019-12-24 08:21:31

问题


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);

来源:https://stackoverflow.com/questions/39569739/the-removing-page-has-already-been-flushed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!