We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Java: Unable to create RTF

Hi Team,

Please check the attached code.
GenerateRTF.zip (1.5 KB)

Here when i use only createDocumentHeader or createTable method it generates proper RTF. If i include both the methods, the RTF is not generated properly. Please let me know whats the issue in my code.

Thanks,
Sukesh

@sukesh.kotian

Thanks for your inquiry. We are looking into the issue and will guide you accordingly.

Any update on this issue?

@tilal.ahmad

Employee Report.zip (1.6 MB)

Check the attachments for details. How can i further increase the size of the sheet to accumulate all the columns.
I checked in MS Word for page layout, it supports only upto 22 inches in width.
Please let me know if there are any other alternatives.

Thanks,
Sukesh

@sukesh.kotian

Thanks for your feedback. Yes, your finding is correct you are getting issue due to page size limitation of MS Word. You can reduce cell size, AutoFitBehavior and set page size to 22 inches to accommodate your table in 22 inches page width. Please check following sample code for reference.

Furthermore, please note by default Document page size is letter so please call document header creation code after table creation to fit it to updated page size.

static void createTable(DocumentBuilder builder) throws Exception {
    com.aspose.words.Table table = builder.startTable();
    builder.getCellFormat().clearFormatting();
    builder.getCellFormat().setWidth(37);
    Color color = new Color(255, 200, 158);

String[] columns = {"Employee Full Name", "Assignment Number", "Employee Number", "Employment Category", "Date Of Hire", "Gender", "Assignment Status", "Date Of Birth", "Job Name", "Position Name", "Marital Status", "Supervisor Full Name", "Payroll Name", "Grade Name", "Social Security Number", "Location Name", "Government Reporting Entity", "Organization Name", "Pay Basis", "Person Type", "Adjusted Service Date", "Latest Hire Date", "Address Line1", "Address City", "Address County", "Address State", "Address Zip", "Length Of Service", "Annual Salary", "Ledger", "Currency Name", "Default Expense Account", "Spinal Point", "Ceiling Point", "Grade Step", "Placement Eff Date", "Bargaining Unit", "Collective Agreement Name", "Revised Sal"};

for (String column : columns) {
        builder.insertCell();
        builder.getFont().setBold(true);
        builder.getFont().setSize(12);
        builder.getCellFormat().getShading().setBackgroundPatternColor(color);
        builder.write(column);
 }
  builder.endRow();

  table.setLeftPadding(3);
  table.setRightPadding(3);
  table.setTopPadding(3);
  table.setBottomPadding(3);
  table.setBorders(LineStyle.SINGLE, 0.5, Color.gray);
  table.setAllowAutoFit(true);
  //table.autoFit(AutoFitBehavior.AUTO_FIT_TO_CONTENTS);
  table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
    
   // builder.getCurrentSection().getPageSetup().setPageWidth(PreferredWidthType.AUTO);
   builder.getCurrentSection().getPageSetup().setPageWidth(22*72);

   builder.endTable();
}
public static void test() throws Throwable, Exception {

   com.aspose.words.Document doc = new com.aspose.words.Document();
   DocumentBuilder builder = new DocumentBuilder(doc);

           
   createTable(builder);
   createDocumentHeader(builder);

   doc.updateFields();
   doc.updateTableLayout();
   doc.save("D:\\Downloads\\GenerateRTF\\test.rtf", com.aspose.words.SaveFormat.RTF);

}