Document doc = new Document();
try {
PdfReader pdfReader = new PdfReader(sourceFile);
PdfCopy pdfCopy = new PdfCopy(doc, new FileOutputStream(
targetFile));
PdfImportedPage impPage = null;
doc.open();
int allPageNum=pdfReader.getNumberOfPages();
for (int i = allPageNum; i > allPageNum- 1; i--) {
impPage = pdfCopy.getImportedPage(pdfReader,i);
pdfCopy.addPage(impPage);
}
} catch (Exception e) {
e.printStackTrace();
}
finally{
doc.close();
}
try {
PdfReader pdfReader = new PdfReader(sourceFile);
PdfCopy pdfCopy = new PdfCopy(doc, new FileOutputStream(
targetFile));
PdfImportedPage impPage = null;
doc.open();
int allPageNum=pdfReader.getNumberOfPages();
for (int i = allPageNum; i > allPageNum- 1; i--) {
impPage = pdfCopy.getImportedPage(pdfReader,i);
pdfCopy.addPage(impPage);
}
} catch (Exception e) {
e.printStackTrace();
}
finally{
doc.close();
}