Here i am combining 2 pdf documents using the Itext packages. Merging was done successfully using the code below
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
document.open();
PdfContentByte cb = writer.getDirectContent();
for (InputStream in : list)
{
PdfReader reader = new PdfReader(in);
for (int i = 1; i <= reader.getNumberOfPages(); i++)
{
document.newPage();
//import the page from source pdf
PdfImportedPage page = writer.getImportedPage(reader, i);
//add the page to the destination pdf
cb.addTemplate(page, 0, 0);
}
}
outputStream.flush();
document.close();
outputStream.close();
Here the list is an InputStream List. And outputStream is an output stream
The problem i am having is i want to append the PDFdocuments in the list after the 1st PDF is added (i.e 1st PDF has 4 lines...i want the 2nd PDF to continue in the same page after the 4th line). What i am getting is the 2nd PDF is added in the second page. Is there any alternate keyword for document.newPage();
Can anyone help me with it.
Thanks would like to hear any responses:)