Excel to PDF: Text is cut and overflows in the next sheet

Hi team,

We are using Aspose Cells v 22.7
input - TURKIYE PETROL RAFINERILERI A.zip (12.0 KB)

output - bundle_25dd31b4-ff3e-41e5-8353-7d2f1694c77b_08.12.2022.17.11.25.395.pdf.zip (100.9 KB)

Using the following code to convert an excel to pdf like so -

public byte[] convertExcelToPDF(ByteArrayInputStream excelInputStream) throws Exception {
        ByteArrayOutputStream outputStreamPdf = new ByteArrayOutputStream();
        try {
            log.info("Initiating Excel to pdf conversion");
            Workbook workbook = new Workbook(excelInputStream);

            // Expanding columns before merging
            WorksheetCollection worksheets = workbook.getWorksheets();
            int workSheetCount = worksheets.getCount();
            for (int sheetNo = 0; sheetNo < workSheetCount; sheetNo++) {
                Worksheet sheet = worksheets.get(sheetNo);
                PageSetup pageSetup = sheet.getPageSetup();
                pageSetup.setPrintArea("");
                pageSetup.setPrintGridlines(true);
                sheet.autoFitRow(0,0,1,new AutoFitterOptions());
                sheet.autoFitColumns();
            }

            PdfSaveOptions saveOptions = new PdfSaveOptions();
            saveOptions.setAllColumnsInOnePagePerSheet(true);

            workbook.save(outputStreamPdf, saveOptions);

            log.info("Conversion from Excel to pdf completed");
            return outputStreamPdf.toByteArray();

        } catch (Exception ex) {
            log.info("Exception occurred while converting Excel to pdf : ", ex);
            throw ex;
        } finally {
            outputStreamPdf.close();
        }
    }

The output has the following issues -

  1. Inconsistent grid.
  2. Text on Page 1 is cut and it spills into Page 2.

Please help and let us know if this is fixable.

Cheers,
Shaurya

@shaurya.chawla,

Thanks for the template XLSX file.

Your PDF file is re-generated or merged by Aspose.PDF. Anyways, I tested your scenario/case using your template Excel file and sample code and found some text is split/clipped onto second page. When you render to PDF via MS Excel, you will also notice this thing. For your needs, you may try to use setOnePagePerSheet option on, this will make sure to render in single page and no text would be split onto second page.
e.g.
Sample code:

Workbook workbook = new Workbook("f:\\files\\TURKIYE PETROL RAFINERILERI A.xlsx");
// Expanding columns before merging
WorksheetCollection worksheets = workbook.getWorksheets();
int workSheetCount = worksheets.getCount();
for (int sheetNo = 0; sheetNo < workSheetCount; sheetNo++) {
Worksheet sheet = worksheets.get(sheetNo);
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setPrintArea("");
pageSetup.setPrintGridlines(true);
sheet.autoFitRow(0,0,1,new AutoFitterOptions());
sheet.autoFitColumns();
}

PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setOnePagePerSheet(true);

workbook.save("f:\\files\\out1.pdf", saveOptions);

I tested using the above code segment and it works as expected, I do not find the text clipped or cut. Please find attached the output PDF file for your reference.
out1.pdf (87.2 KB)

This is not an issue. Please open the output PDF (by Aspose.Cells) into Adobe reader and set its zoom level to higher value (e.g., >=125%). Now you can see the gridlines are there for the data/table.