Split table horizontally

Hi all,
I’m trying to develop a tool that creates PDF files containing tables with different measures.
When I find oversized tables, like the one attached below, I have some issues visualizing them.
Is it possible to split them horizontally? For instance, if, like in this case, the page is smaller than the table, how can I break the column “Other” to make it go on a new page/line?

Untitled.png (25.8 KB)

I’m using Aspose.PDF in its Java version.

Thanks in advance

@irpps

When you add a table inside PDF document, it automatically breaks itself to subsequent pages if it exceeds the Page Size. In case you want to keep exceeding column with the next page, you can try using table.setRepeatingColumnsCount() property and set the column number in it. In case it does not fulfil your requirements, please share your complete sample code snippet along with an expected output file so that we can test the scenario in our environment and address it accordingly.

I tried to add table.setRepeatingColumnsCount() but it does not work.

if(indicatorInstance.getAttributeList().size() == 3) {
                            Attribute firstColumnAttribute = indicatorInstance.getAttributeList().get(0);
                            Table table = new Table();
                            table.setBorder(new BorderInfo(BorderSide.All, .1f, Color.getBlack()));
                            table.setDefaultCellBorder(new BorderInfo(BorderSide.All, .1f, Color.getBlack()));
                            /* String columnWidths = "";
                            double columnWidthsValue = 100 / (firstColumnAttribute.getValueList().size() + 1);

                            for(int i = 0; i <= (firstColumnAttribute.getValueList().size() + 1); i++) {
                                columnWidths += columnWidthsValue + "% ";
                            }
                            table.setColumnWidths(columnWidths);*/

                            MarginInfo marginInfo = new MarginInfo();
                            marginInfo.setTop(10);
                            marginInfo.setBottom(15);
                            marginInfo.setLeft(10);
                            marginInfo.setRight(10);
                            table.setDefaultCellPadding(marginInfo);
                            table.setAlignment(HorizontalAlignment.Center);

                            Row indicatorNameRow = table.getRows().add();
                            TextFragment indicatorNameLabel = new TextFragment(indicatorInstance.getIndicator().getName());
                            indicatorNameLabel.getTextState().setFont(FontRepository.openFont(fontPath));
                            indicatorNameLabel.getTextState().setForegroundColor(Color.fromArgb(91, 87, 164));
                            indicatorNameLabel.getTextState().setFontSize(10);
                            indicatorNameLabel.getTextState().setFontStyle(FontStyles.Bold);

                            Cell cell = indicatorNameRow.getCells().add();
                            cell.getParagraphs().add(indicatorNameLabel);
                            cell.setAlignment(HorizontalAlignment.Center);
                            cell.setColSpan((firstColumnAttribute.getValueList().size()+1) * indicatorInstance.getAttributeList().get(1).getValueList().size());

                            Row firstAttributeRow = table.getRows().add();

                            Cell emptyCell = firstAttributeRow.getCells().add();
                            emptyCell.setColSpan(indicatorInstance.getAttributeList().get(1).getValueList().size());

                            for(Value value : firstColumnAttribute.getValueList()) {

                                TextFragment valueLabel = new TextFragment(value.getValue());
                                valueLabel.getTextState().setFont(FontRepository.openFont(fontPath));
                                valueLabel.getTextState().setForegroundColor(Color.fromArgb(34, 34, 34));
                                valueLabel.getTextState().setFontSize(10);
                                valueLabel.getTextState().setFontStyle(FontStyles.Bold);

                                Cell valueCell = firstAttributeRow.getCells().add();
                                valueCell.getParagraphs().add(valueLabel);
                                valueCell.setAlignment(HorizontalAlignment.Center);
                                valueCell.setColSpan(indicatorInstance.getAttributeList().get(1).getValueList().size());
                            }

                            Row secondAttributeValuesRow = table.getRows().add();
                            Cell secondRowEmptyCell = secondAttributeValuesRow.getCells().add();
                            secondRowEmptyCell.setColSpan(indicatorInstance.getAttributeList().get(1).getValueList().size());

                            for(int i = 0; i< indicatorInstance.getAttributeList().get(0).getValueList().size(); i++) {
                                for (Value value2 : indicatorInstance.getAttributeList().get(1).getValueList()) {

                                    TextFragment secondAttributeLabel = new TextFragment(value2.getValue());
                                    secondAttributeLabel.getTextState().setFont(FontRepository.openFont(fontPath));
                                    secondAttributeLabel.getTextState().setForegroundColor(Color.fromArgb(34, 34, 34));
                                    secondAttributeLabel.getTextState().setFontSize(10);
                                    secondAttributeLabel.getTextState().setFontStyle(FontStyles.Regular);

                                    Cell secondAttributeCell = secondAttributeValuesRow.getCells().add();
                                    secondAttributeCell.getParagraphs().add(secondAttributeLabel);
                                    secondAttributeCell.setAlignment(HorizontalAlignment.Center);
                                    secondAttributeCell.setColSpan(1);

                                }
                            }

                            Attribute columnAttribute = indicatorInstance.getAttributeList().get(2);

                            for (Value value : columnAttribute.getValueList()) {

                                Row valuesRow = table.getRows().add();

                                TextFragment thirdAttributeLabel = new TextFragment(value.getValue());
                                thirdAttributeLabel.getTextState().setFont(FontRepository.openFont(fontPath));
                                thirdAttributeLabel.getTextState().setForegroundColor(Color.fromArgb(34, 34, 34));
                                thirdAttributeLabel.getTextState().setFontSize(10);
                                thirdAttributeLabel.getTextState().setFontStyle(FontStyles.Regular);

                                Cell valuesRowAttributeCell = valuesRow.getCells().add();
                                valuesRowAttributeCell.setAlignment(HorizontalAlignment.Center);
                                valuesRowAttributeCell.setColSpan(indicatorInstance.getAttributeList().get(1).getValueList().size());
                                valuesRowAttributeCell.getParagraphs().add(thirdAttributeLabel);

                                for (ValueInstance valueInstance : indicatorInstance.getValueInstanceList()) {
                                    for (Value value1 : indicatorInstance.getAttributeList().get(0).getValueList()) {
                                        for (Value value2 : indicatorInstance.getAttributeList().get(1).getValueList()) {
                                            if (valueInstance.getValues().contains(value1) && valueInstance.getValues().contains(value2) && valueInstance.getValues().contains(value)) {
                                                TextFragment valueLabel = new TextFragment(valueInstance.getValue());
                                                valueLabel.getTextState().setFont(FontRepository.openFont(fontPath));
                                                valueLabel.getTextState().setForegroundColor(Color.fromArgb(34, 34, 34));
                                                valueLabel.getTextState().setFontSize(10);
                                                valueLabel.getTextState().setFontStyle(FontStyles.Regular);

                                                Cell valueCell = valuesRow.getCells().add();
                                                valueCell.getParagraphs().add(valueLabel);
                                                valueCell.setAlignment(HorizontalAlignment.Center);
                                                valueCell.setColSpan(1);
                                            }
                                        }
                                    }
                                }
                            }

                            page = document.getPages().add();
                            page.getPageInfo().setLandscape(true);
                            table.setRepeatingColumnsCount(5);
                            page.getParagraphs().add(table);

                            page.getParagraphs().add(emptyTextFragment);

                            Row imageRow = table.getRows().add();
                            File folder = new File(serverPath);
                            int k = 0;
                            if(folder.exists() && folder.isDirectory()) {
                                for(File f : folder.listFiles()) {
                                    if(f.getName().contains("output_"+indicatorInstance.getId())) {
                                        com.aspose.pdf.Image img1 = new com.aspose.pdf.Image();
                                        img1.setFile(serverPath + "output_" + indicatorInstance.getId() + "_v_"+k+".png");
                                        img1.setFixWidth(150);
                                        img1.setFixHeight(150);

                                        Cell imageCell = imageRow.getCells().add();
                                        imageCell.setAlignment(HorizontalAlignment.Center);
                                        imageCell.setColSpan(firstColumnAttribute.getValueList().size());
                                        imageCell.getParagraphs().add(img1);
                                        k++;
                                    }
                                }
                            }

                            page = document.getPages().add();

                        }

I would like to make the table smaller in order to make it fit to the page in its width. How can I do that?

@irpps

Please try to use ColumnAdjustment Property in order to fit the table according to the Page dimensions. In case you still face any issues, please share your complete code snippet with us so that we can test the scenario in our environment and address it accordingly.