Problems with borders in tables

I’m new to Aspose, so i apologise if i’ve missed something obvious.


I creating a data table with a number of rows, however I’m having problems with the table stretching across multiple pages and messing up the cell borders.

This snippet of java code can be used to reproduce the problem:

public static void main(String[] args) throws Exception {
Pdf pdf = new Pdf();
Section s = new Section();
pdf.getSections().add(s);
s.isLandscape(true);

Table table = new Table(s);

//Set default cell border using BorderInfo object
table.setDefaultCellBorder(new BorderInfo(BorderSide.All, 0.1F));

//Set table border using another customized BorderInfo object
table.setBorder(new BorderInfo(BorderSide.All, 1F));

//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();

margin.setLeft(5f);
margin.setRight(5f);
margin.setTop(5f);
margin.setBottom(5f);

//Set the default cell padding to the MarginInfo object
table.setDefaultCellPadding(margin);

for (int i = 0; i< 100; i++) {
Row r = table.getRows().add();
r.getCells().add(i + “-1”);
r.getCells().add(i + “-2”);
r.getCells().add(i + “-3”);
}

s.getParagraphs().add(table);


System.out.println(“123”);
pdf.save(“C:\temp\” + System.currentTimeMillis() + “.pdf”);
}

For info we’re using version 4.5.0 of the aspose-pdf.jar

Hi Matthew,

Thanks for using our API’s.

In order to generate the correct output, I would recommend you to please try using Document Object Model approach of com.aspose.pdf package. Please try using the following code snippet to generate the correct output. For your reference, I have also attached the output generated with Aspose.Pdf for Java 4.5.0.

Java

// create Document instance
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();

// add page to PDF document
doc.getPages().add();
doc.getPages().get_Item(1).getPageInfo().setLandscape(true);

// create table object
com.aspose.pdf.Table table = new com.aspose.pdf.Table();

// Set default cell border using BorderInfo object
table.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 0.1F));

// Set table border using another customized BorderInfo object
table.setBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 1F));

// Create MarginInfo object and set its left, bottom, right and top margins
com.aspose.pdf.MarginInfo margin = new com.aspose.pdf.MarginInfo();

margin.setLeft(5f);
margin.setRight(5f);
margin.setTop(5f);
margin.setBottom(5f);

// Set the default cell padding to the MarginInfo object
table.setDefaultCellPadding(margin);

// Create rows
for (int i = 0; i < 100; i++) {
    com.aspose.pdf.Row r = table.getRows().add();
    r.getCells().add(i + "-1");
    r.getCells().add(i + "-2");
    r.getCells().add(i + "-3");
}

// Add table to the PDF document
doc.getPages().get_Item(1).getParagraphs().add(table);

System.out.println("123");

doc.save("C:\\pdftest\\" + System.currentTimeMillis() + ".pdf");