Free Support Forum - aspose.com

Aspose Cells -> Word Wrap feature not working when saving the workbook as PDF

I am applying word wrap for all the cells in the worksheet as:
var wrap = wb.CreateStyle(); wrap.VerticalAlignment = TextAlignmentType.Center;
wrap.HorizontalAlignment = TextAlignmentType.Center; wrap.IsTextWrapped = true;
cells.ApplyStyle(wrap, new StyleFlag() { WrapText = true, HorizontalAlignment = true, VerticalAlignment = true });

It shows fine for the .ODS file but when save a new workbook as PDF it doesn’t word wrapping and loses content as per Picture1Picture1.PNG (38.9 KB)

Found a temporary solution as per forum: Word wrap not working in pdf output (AutoFitRows()) but now the page content is of poor quality (too much space between rows and between fields, font small…). Please see Picture2
Just want to find a solution to look unchanged as per Picture1 but to Word Wrap the content below. Thanks in advancePicture2.PNG (26.6 KB)

@Remus87,

Could you try to use AutoFitRows(true) if it works for your needs.
If you still find the issue, kindly do provide your input file, output ODS and PDF files and complete sample code (runnable) to reproduce the issue on our end, we will check it soon.

I’ve created a clone project and removed all the other functionalities (was above 1000 lines of code) and left just a simple method for the current issue. You’ll see in comments Issue 1 and another small bit on cell B1 want to overwrite the IsWrapedText setting and to set it to false also commented as Issue 2. The produced files are inside the project (LMQuery.ods and LMQuery.pdf).
If you can try please with commented: worksheet.AutoFitRows(true); and then uncomment that line to see the difference.

@Remus87,

As requested earlier, kindly do create a separate console application (runnable) and provide your input file, output ODS and PDF file to reproduce the issue on our end, we will check it soon.

Hi Amjad !
I forgot to attach the project on the last message. I made it now a Console Application as well (was WinFormsSampleProject.zip (133.5 KB)
)

@Remus87,

Thanks for the sample.

We will check it soon.

Hi! Just wonder if any solution found yet.
You are a great team. Thanks!

@Remus87,

After an initial test, I am able to reproduce the issue as you mentioned. I found word wrap feature is not working when saving to PDF. But we need to evaluate your issue thoroughly as it is quite possible that your code might need some tweak. I have logged a ticket with an id “CELLSNET-47709” for your issue.

We will look into it soon.

Once we have an update on it, we will let you know.

Thanks for the update

@Remus87,
It works OK with the following code:

Workbook wb = new Workbook("LMQuery.ods");

wb.Worksheets["Sheet1"].AutoFitRows(true);

wb.Save("output_autofitRows(ture).pdf");

The output file is attached: output_autofitRows(true).pdf (119.2 KB)

Hi
The solution provided didn’t work for my scenario as it doesn’t only resume on instantiating a worbook of ods type and just Save it. As per the messaging history of the opened ticket I provided a sample executable with a bit more processing as setting the column width if exists and other small style formatting that probably won’t enable the AutoFitRows property

@Remus87,

You can add the following lines of code to your sample project before saving to ODS and PDF file:

foreach(Worksheet sheet in wb.Worksheets)
{
    sheet.AutoFitRows(true);
}

For code location, see the attached screenshot: “code_location.png”.
code_location.png (19.4 KB)

Hope, this helps a bit.

Thanks for the fix Amjad. It’s the perfect solution

@Remus87,

We are glad that your issue is sorted out by the suggested code segment. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.