Free Support Forum - aspose.com

Rtf file Table cells width alignment issue


#1

Hi,


I am creating Rtf file by using aspose words.
Please find the attachments.
If table contains more then 20 columns , the table column cells width alignment is not properly.

This is my code.


" Table table = builder.startTable();
builder.getCellFormat().clearFormatting();
builder.getCellFormat().setWidth(100);

for (Map<String,Object> map: columns) {
insertCell(builder);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.YELLOW);
builder.getCellFormat().setWidth(100);
builder.write((String) map.get(“columnName”));
}
builder.endRow();
for (Map<String,Object> map: columns) {
String colName = (String) map.get(“columnName”);
colName = colName.toUpperCase().replaceAll(" “, “_”);
insertCell(builder);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
builder.getCellFormat().setWidth(100);
builder.write(”{{"+colName+"}}");
}
table.setCellSpacing(1);
builder.endTable();"

Above code generates rtf file but columns are alignment is not properly.
My requirement is :
1. I want to increase the page width automatically based on table and columns names width.
2. All columns names should come in one line
3. Suppose if table contains 100 columns with large column names then page size need to increase automatically and all columns should come in one single line not in multiple lines, and also header size also need to increase up to page size.

Please provide the code related to my requirement.


#2

Hi Trinath,


Thanks for your inquiry.

Trinath:
1. I want to increase the page width automatically based on table and columns names width.
You can sum all widths of cells in first row (use Cell.CellFormat.Width property) and then use PageSetup.PageWidth property to increase width.

Trinath:
2. All columns names should come in one line
You may try different Table.AutoFit options e.g. <span style=“font-family: “Courier New”; font-size: 9pt; background-color: rgb(255, 255, 255);”>table.autoFit(AutoFitBehavior.<span style=“font-family: “Courier New”; font-size: 9pt; color: rgb(102, 14, 122); font-weight: bold; font-style: italic;”>AUTO_FIT_TO_CONTENTS<span style=“font-family: “Courier New”; font-size: 9pt; background-color: rgb(255, 255, 255);”>);

Trinath:
3. Suppose if table contains 100 columns with large column names then page size need to increase automatically and all columns should come in one single line not in multiple lines, and also header size also need to increase up to page size.
MS Word imposes limit on max width size i.e. 22 inches max. You can’t increase width of page larger than 22 inches. Perhaps, you should somehow reduce number of columns in table.

Regarding simple (11).rtf, to ensure a timely and accurate response, please attach the following resources here for testing:

  • Your expected document which shows the correct output. Please create this document using Microsoft Word application.
  • Your code has compile time errors e.g. definition of insertCell method is missing. Please create a standalone Java application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

#3

HI Awais Hafeez,



Please find the attachment.

I am facing an issue with pdf file generation it is also taking same width max 22 inches because i am generating pdf file from rtf file , is their any way to expand table width in pdf file?


Rtf page size is fixed (max 22 inches) , but in pdf page size is not fixed , but still i am getting same table width in pdf also , i need to increase table cells width in pdf file based on column names width.




#4

Hi Trinath,


Thanks for your inquiry. In this case, the following simple code helps in achieving what you’re looking for:

<pre style=“font-family: “Courier New”; font-size: 9pt;”>Document doc = new Document(“D:\temp\rtf+file+issue\out.rtf);

doc.getFirstSection().getPageSetup().setPageWidth(
50 * 72);
doc.
updateTableLayout();

doc.save(
“D:\temp\rtf+file+issue\16.6.0.pdf”);

Best regards,