Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Aspose.pdf version 3.3 issue :Tables are getting overlapped on header

$
0
0
Hi ,

I am using Aspose.pdf jar with version as 3.3. I have created headers ,table and footers in pdf.

but the problem is Table is getting overlapped on header (ideally table should be created after header is set on page,this is how aspose.pdf behaves).Recently I just upgraded the version to 3.3 from 3.1.0 and I caught this issue.Although from next page tables are coming after header which is correct.

Sample Code snippet-
Pdf pdf = new Pdf();
for(int i=0;i<3;i++){
Section sec1 = pdf.getSections().add();
HeaderFooter Header1 = new HeaderFooter(sec1);
//Set the header of odd pages of the PDF document
sec1.setOddHeader(Header1);
sec1.setEvenHeader(Header1);
//Enable this header for first page only
//Header1.setIsFirstPageOnly(true);

//Instantiate a Text paragraph that will store the content to show as header
Text text = new Text("Sample header Text \n" +
"Sample header Text\n" +
"Sample header Text\n" +
"Sample header Text\n" +
"Sample header Text\n" +
"Sample header Text\n" +
"Sample header Text\n" +
"PSample header Text\n" +
"Sample header Text\n" +
"Sample header Text\n");
// specify the font color information for text object
text.getTextInfo().setColor(new aspose.pdf.Color("Green"));
//specify the font name as Arial
text.getTextInfo().setFontName("Arial");
// set the top margin informatin for Header as 20
Header1.getMargin().setTop(20);
//Add the text object to the Paragraphs collection of HeaderFooter object to
//display header on the pages of PDF document
Header1.getParagraphs().add(text);
// ======= In following code we will create a Table =======//
// create a new Table object
Table Table1 = new Table(sec1);
// specify the Column width information for Table object
//Table1.setColumnWidths("70 70");
// specify the Border information for Table
Table1.setDefaultCellBorder(new BorderInfo(BorderSide.All.getValue(), 0.9F, new aspose.pdf.Color("Black")));
// Set the BackGround color information for Tabel as Yellow
Table1.setBackgroundColor(new aspose.pdf.Color("White"));
Table1.setIsFirstRowRepeated(true);
Table1.setWidth(sec1.getPageInfo().getPageWidth() - 5);
//Table1.setColumnAdjustment(ColumnAdjustmentType.AutoFitToContent);
int rowCount = 0;
for(int j=1;j<10;j++){
Row row21 = Table1.getRows().add();
row21.setFixedRowHeight(15);
if(j==1){
for(int k = 0;k<10;k++){{
Cell cell= row21.getCells().add("Ankit");
cell.setWidth(20);
cell.setHeight(20);
cell.setBackgroundColor(new aspose.pdf.Color("White"));// specify the BackGround color information for  cell of Row
cell.setAlignment(AlignmentType.Center);// specify the Horizontal Alignment information for  cell of Row
cell.setVerticalAlignment(VerticalAlignmentType.Center);// specify the Vertical Alignment information for  cell of Row
cell.getDefaultCellTextInfo().setColor(new aspose.pdf.Color("Black"));// specify the Text Color information for  cell of Row
cell.getDefaultCellTextInfo().setFontSize(10);
Table innerTable = new Table();
Row row = innerTable.getRows().add();
row.getCells().add("Child");
cell.getParagraphs().add(innerTable);
}
}
}
else{
for(int k = 0;k<10;k++){
Cell cell= row21.getCells().add("Col"+rowCount+k);
cell.setWidth(20);
cell.setHeight(20);
cell.setBackgroundColor(new aspose.pdf.Color("White"));// specify the BackGround color information for  cell of Row
cell.setAlignment(AlignmentType.Center);// specify the Horizontal Alignment information for  cell of Row
cell.setVerticalAlignment(VerticalAlignmentType.Center);// specify the Vertical Alignment information for  cell of Row
cell.getDefaultCellTextInfo().setColor(new aspose.pdf.Color("Black"));// specify the Text Color information for  cell of Row
cell.getDefaultCellTextInfo().setFontSize(10);
}
}
// add a cell to first row of Table
rowCount++;
}
// add table to paragraphs collection of section object   
sec1.getParagraphs().add(Table1);
//set footer
HeaderFooter footer = new HeaderFooter(sec1);
// specify the Alignment information for the contents of HeaderFooter as Center Aligned 
footer.getTextInfo().setAlignment(AlignmentType.Center);
// set the font color information for HeaderFooter object as Red
footer.getTextInfo().setColor(new aspose.pdf.Color("Red"));
// create a sample text object with special replaceabel symbols
Text footText = new Text(footer, "Page: $p / $P");
// add text object to paragraphs collection of HeaderFooter object
footer.getParagraphs().add(footText);
// set above create HeaderFooter object as Odd Footer for section1
sec1.setOddFooter(footer);
// set above create HeaderFooter object as Even Footer for section1
sec1.setEvenFooter(footer);
}
pdf.save("D:\\pdftest\\Resultant.pdf"); 

Please look into this.

Thanks and best Regards,
Ankit

Viewing all articles
Browse latest Browse all 3131

Trending Articles