我有以下方法将页面缩小到 50% :
private void shrinkDocuments(List<PdfDocument> documentsToBeMerged){
for (PdfDocument pdfDoc : documentsToBeMerged) {
for (int p = 1; p <= pdfDoc.getNumberOfPages(); p++) {
PdfPage page = pdfDoc.getPage(p);
Rectangle media = page.getCropBox();
if (media == null) {
media = page.getMediaBox();
}
// Shrink the page to 50%
Rectangle crop = new Rectangle(0, 0, media.getWidth() / 2, media.getHeight() / 2);
page.setMediaBox(crop);
page.setCropBox(crop);
}
pdfDoc.close();
}
}
调试我看到程序抛出一个com.itextpdf.kernel.PdfException: Document was closed. It is impossible to execute action
.
我该如何解决这个问题?我怎样才能再次打开这个文件?