Add page dynamically to pdf with header and footer

Hello,

We are making an Android application that generates the pdf using some data.
We have used the Aspose.Pdf for Android 1.6.0 in our application.

we are trying to add page dynamically as per content with header and footer

What we are trying
  1. Add page dynamically when text comes at last position of page
  2. Add table to header

Facing issue

  1. Add page dynamically when text comes at last position of page.
:- when we do manually like Page m_page2 = m_doc.getPages().add(); , it works fine , but i dont know about the length of the content of that page , so need to add page dynamically .so can you please suggest me how we can achieve this

  1. Add table to header
:- we tried with text as header but when we try to add table as header it wont work
Table m_header = new Table();
m_header.getMargin().setLeft(- 90d);
m_header.getMargin().setTop(- 70d);
p_doc.getPages().get_Item(m_pageCounter).getParagraphs().add(m_header);
m_header.setColumnWidths("600");
m_header.setVerticalAlignment(VerticalAlignment.Bottom);
Row m_headerRow = m_header.getRows().add();
m_headerRow.setFixedRowHeight(45);
m_headerRow.getCells().add().getParagraphs().add(p_image);

 p_doc.getPages().get_Item(m_pageCounter).getParagraphs().add(m_header);


Please help us

Thanks





Hi there,

java.webline:

  1. Add page dynamically when text comes at last position of page.
:- when we do manually like Page m_page2 = m_doc.getPages().add(); , it works fine , but i dont know about the length of the content of that page , so need to add page dynamically .so can you please suggest me how we can achieve this


Thanks for your inquiry. Please note while creating a new PDF, if contents increase from one page height API automatically add a new page. We will appreciate it if you please share your sample code here, we will test the scenario and will update you accordingly.

Best Regards,

Hi

Yes you are right page automatically added and content manage into it but my question is that how we can manage header and footer to the new page . Page content is manage into new page but it consider as one page


Pl let me know about this issue

Thanks

Hi there,


Thanks for your feedback. Please check following code snippet to add add header/footer to PDF document. You may notice that data is moving to next pages automatically and header/footer assigned to pages as well. Hopefully it will help you to accomplish the task.

Document doc = new Document();

Page page = doc.getPages().add();

page.getParagraphs().add(
new TextFragment(“page-1”));

Table table =
new Table();

table.setColumnWidths(
“50 100”);


for (int i = 1; i <= 200; i++)

{

Row row = table.getRows().add();

row.setFixedRowHeight(
15);

Cell cell1 = row.getCells().add();

cell1.getParagraphs().add(
new TextFragment("Content 1 "+i));

Cell cell2 = row.getCells().add();

cell2.getParagraphs().add(
new TextFragment("Content 2 "+i));

}

page.getParagraphs().add(table);



//header table

com.aspose.pdf.Table table1 = new com.aspose.pdf.Table();

table1.setColumnWidths(
“150 150”);

com.aspose.pdf.Row row1 = table1.getRows().add();

//add table cells

row1.getCells().add(“Column 1”);

row1.getCells().add(
“Column 2”);

row1.setBorder(
new com.aspose.pdf.BorderInfo(BorderSide.Bottom, .5f, com.aspose.pdf.Color.getLightGray()));



com.aspose.pdf.HeaderFooter header =
new com.aspose.pdf.HeaderFooter();

header.getParagraphs().add(table1);

page.setHeader(header);

doc.save(outputPath);<o:p></o:p>

Please feel free to contact us for any further assistance.


Bet Regards,