Excel to PDF conversion - Auto-fit columns truncates text in .NET

We have an issue with the Aspose.Cells library.

We tried to convert the EXCEL files in the folder Input_Files(look in attachments) with an application(in the attachments) to PDFA files. This application fits the columns and rows from the Excel file to a PDFA file.

worksheet.PageSetup.PrintArea = null;
worksheet.AutoFilter.Range = null;
worksheet.AutoFitColumns();
worksheet.AutoFitRows();

var saveOptions = new Aspose.Cells.PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf);
saveOptions.Compliance = Aspose.Cells.Rendering.PdfCompliance.PdfA1b;
saveOptions.AllColumnsInOnePagePerSheet = true;
excel.Save(pdf, saveOptions);

We observe that content of cells get truncated in the Output file (see attachments Output_Files folder) and we don’t know why.
Furthermore the cell height in some lines do not fit in one of the output document (…_xl_xls_xlsx).

On the machine we save the spreadsheet to PDFA format, the font used is not available/installed. The api documentation states that a fallbackfont (MSArialUnicode) is then used instead.

sample files with input and outputfiles:
FONTS_ERROR_ASPOSE.zip (100.6 KB)

We used following Aspose library:

  • Aspose.Cells: 18.3

@bck

Thanks for using Aspose APIs.

Please pass true as parameter in the AutoFitRows() method. It means, it will not autofit those rows whose heights have already been defined by the user.

Please see the output pdf generated by the following code and its comment for a reference.

Download Link:
Output Pdf.zip (54.8 KB)

C#

var saveOptions = new Aspose.Cells.PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf);
saveOptions.Compliance = Aspose.Cells.Rendering.PdfCompliance.PdfA1b;
saveOptions.AllColumnsInOnePagePerSheet = true;

string fileName = "繁體中文xl.xls.xlsx";

var excel = new Workbook(fileName);

foreach (Worksheet worksheet in excel.Worksheets)
{
    worksheet.PageSetup.PrintArea = null;
    worksheet.AutoFilter.Range = null;
    worksheet.AutoFitColumns();
    worksheet.AutoFitRows(true); //This line is important, pass true as parameter
}

excel.Save(fileName + ".out.pdf", saveOptions);