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

Free Support Forum - aspose.com

First few rows not reflecting in converted pdf

Hi team,

Here’s the code we’re using to convert excel to pdf. we’re using Cells version 22.7 and Pdf version 22.6.

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);
                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();
        }

Here is the file we’re trying to convert - staticData (18).zip (25.6 KB)

Upon observation, the first 2 rows don’t show up in the converted document.
Please advise on a solution.

Regards,
shaurya

@shaurya.chawla,

Thanks for the template file.

This is not an issue with Aspose.Cells APIs. I checked your file by opening the file into MS Excel manually, I found there is printable area set (in Page Setup dialog, Sheet|Print area tab) so that’s why first few rows/cols are skipped when rendering to PDF. You need to remove the printable area of the sheet(s) and then render to PDF. You can also remove print area in code. See the updated code segment that you may try:
e.g.
Sample code:

.......
// 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("");
      sheet.autoFitColumns();
}

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

I tested the updated code segment and it works as expected.

Let us know if you still have any issue or queries.

1 Like

Thanks for your reply Amjad!

I will try this and let you know.

Thanks a lot :slight_smile: