Articles in this section
Category / Section

How to avoid the Wrap Text issue in Excel to PDF conversion

2 mins read

Syncfusion XlsIO converts Excel documents with wrap text set in Excel cells to PDF properly. But there is  an unique case in which the wrap text is set in the cell but the row height is not serialized in XML.

Microsoft Excel can automatically reset the row height during Excel to PDF conversion. But Syncfusion XlsIO cannot do this automatically.

Calling the AutofitRows method of IRange interface before loading the workbook to ExcelToPdfConverter would auto-fit the row height of cells, before being converted to PDF document.

The following complete code snippet explains this.

C#

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Excel2016;
    IWorkbook workbook = application.Workbooks.Open("../../Data/Template.xlsx");
    IWorksheet worksheet = workbook.Worksheets[0];
 
    //Autofit Rows
    worksheet.UsedRange.AutofitRows();
 
    ExcelToPdfConverter converter = new ExcelToPdfConverter(workbook);
    PdfDocument document = converter.Convert();
 
    document.Save("Output.pdf");
    System.Diagnostics.Process.Start("Output.pdf");
}

 

VB.NET

Using excelEngine As ExcelEngine = New ExcelEngine
    Dim application As IApplication = excelEngine.Excel
    application.DefaultVersion = ExcelVersion.Excel2016
    Dim workbook As IWorkbook = application.Workbooks.Open("../../Data/Template.xlsx")
    Dim worksheet As IWorksheet = workbook.Worksheets(0)
 
    'Autofit Rows
    worksheet.UsedRange.AutofitRows()
 
    Dim converter As ExcelToPdfConverter = New ExcelToPdfConverter(workbook)
    Dim document As PdfDocument = converter.Convert()
 
    document.Save("Output.pdf")
    System.Diagnostics.Process.Start("Output.pdf")
End Using

 

A complete working sample can be downloaded from WrapTextInExcelToPDF.Zip.

Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheet or workbook, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to worksheet using Template Markers, and most importantly PDF and Image conversions with code examples.

Refer here to explore the rich set of Syncfusion Essential XlsIO features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied