RTF template width is not accommodating for all columns horizontally

Hello,

I am facing an issue where we are generating RTF template with high column count or column width. When the overall column width exceeds a certain value it starts clipping the column at the right end (Example file image is attached). Currently we are setting the template orientation as landscape. Is there a way we can fix this without changing other configuration in place.

private void createRTFSimple(OutputStream out, Map<String, Object> rtfTemplateLayout, String imagePath) throws Exception {
    	logger.info("Enter in createRTFSimple() imagePath: {}",imagePath);
        Document doc = new Document();
        builder = new DocumentBuilder(doc);
        createDocumentHeader(imagePath);
        builder.moveToDocumentStart();
        builder.getFont().setSize(9);
        builder.getFont().setName("Arial");
        builder.writeln("{{#foreach REPORT_DATA}}");
        builder.writeln("{{#foreach PARAMETERS}}");
        createRTFParametersTable(rtfTemplateLayout);
        logger.info("in createRTFSimple() after createRTFParametersTable");
        builder.writeln("{{/foreach PARAMETERS}}\n");
        createSimpleTable(rtfTemplateLayout);
        builder.writeln("{{/foreach REPORT_DATA}}");

        for (Section sec : doc.getSections()) {
            PageSetup pageSetup = sec.getPageSetup();
            pageSetup.setOrientation(com.aspose.words.Orientation.LANDSCAPE);
            pageSetup.setRightMargin(20);
            pageSetup.setLeftMargin(20);
            pageSetup.setPaperSize(PaperSize.TABLOID);
        }

        doc.updateTableLayout();
        doc.save(out, SaveFormat.RTF);
        logger.info("end in createRTFSimple()");
    }

 private void createSimpleTable(Map<String, Object> rtfTemplateLayout) throws Exception {
    	logger.info("start createSimpleTable()");
        Table table = builder.startTable();
        builder.getCellFormat().clearFormatting();
        builder.getCellFormat().setWidth(100);

        List<Map<String, Object>> columns = (List<Map<String, Object>>) rtfTemplateLayout.get("reportColumns");

        for (Map<String, Object> map : columns) {
            builder.insertCell();
            builder.getFont().setBold(true);
            builder.getFont().setSize(9);
            builder.getFont().setColor(Color.WHITE);
            builder.getCellFormat().getShading().setBackgroundPatternColor(HEADER_COLOR);
            builder.write((String) map.get("columnName"));
        }
        builder.endRow();
        builder.getFont().setColor(Color.BLACK);
        Boolean isStart = Boolean.TRUE;
        for (Map<String, Object> map : columns) {
            String colName = (String) map.get("columnName");
            String alignment = (String) map.get("alignment");
            colName = colName.toUpperCase();
            colName = SplashUtils.replaceSpecialCharacters(colName, "_");
            insertCell();
            builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);

            if ("CENTER".equalsIgnoreCase(alignment))
                builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
            else if ("RIGHT".equalsIgnoreCase(alignment))
                builder.getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);
            else
                builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);

            if (isStart) {
                builder.write("{{#foreach REPORT_COLUMNS}} ");
                isStart = Boolean.FALSE;
            }
            builder.write("{{" + colName + "}}");
        }
        logger.info("in createSimpleTable() after columns loop");
        builder.write("\n{{/foreach REPORT_COLUMNS}}");
        builder.getCurrentSection().getPageSetup().setPageWidth(PreferredWidthType.AUTO);
        table.autoFit(AutoFitBehavior.AUTO_FIT_TO_CONTENTS);
        table.setBorders(LineStyle.SINGLE, 0.5, Color.gray);
        table.setLeftPadding(3);
        table.setRightPadding(3);
        table.setTopPadding(3);
        table.setBottomPadding(3);
        builder.endTable();
        logger.info("end createSimpleTable()");
    }

@psharma314 Use the following code to fit the table:

table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
table.setPreferredWidth(PreferredWidth.fromPercent(100));