Below is a combination of PDF and add the page number code:
Public static InputStream myTest (List
The Document Document=null;
InputStream bis=null;
ByteArrayOutputStream bos=null;
Try {
A Rectangle the rect=new Rectangle (PageSize. A4);
The document=new document (the rect);
Bos=new ByteArrayOutputStream ();
PdfCopy copy=new PdfCopy (document, bos);
document.open();
Int pages=0;//the current page number
for (int i=0; i
PdfReader reader=new PdfReader (files. Get (I));
PdfCopy. PageStamp stamp;//insert page Numbers don't required page can be deleted
Int n=reader. GetNumberOfPages ();
For (int j=1; J & lt;=n; J++) {
A Rectangle pageSize=reader. GetPageSize (1);
Double width=pageSize. GetWidth ();
Pages++;
Document. Brought ();
PdfImportedPage page=copy. GetImportedPage (reader, j);
Stamp=copy. CreatePageStamp (page);//insert page Numbers don't required page can be deleted
ColumnText. ShowTextAligned (stamp. GetUnderContent (), Element. ALIGN_CENTER, new Phrase (addFont (the String. Format (" first "+ pages +" page "))), (int) width * 0.5 f, 100 f, 0 f);//insert page number needed
//don't page can be deleted
Stamp. AlterContents ();//insert page Numbers don't required page can be deleted
Copy. The addPage (page);
}
Reader. The close ();
}
Copy. The close ();
} the catch (IOException e) {
e.printStackTrace();
} the catch (DocumentException e) {
e.printStackTrace();
} the finally {
Document. The close ();
}
The bis=new ByteArrayInputStream (bos toByteArray ());
Return the bis.
}