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

Free Support Forum - aspose.com

Different Word and PDF output when table row height rule is set to auto

Hi,
We are going to use Aspose Words to insert images to the document. Images and image captions are inserted into a table. The first row contains images and the second row contains captions.
The row height rule for the first row is set to HeightRule.Exactly. The row height rule for the second row is set to HeightRule.Auto to accommodate any number of characters.
When document is saved as .docx it looks good as expected. When document is saved as .pdf, the height of the second row becomes equal to the height of the first row regardless of number of characters.
I was trying to find a workaround by getting a height of the text upfront and set the height of the second row in the same way as I did for the first row, but no success.
Attached are 3 files: file with source C# code, .docx and .pdf.
Thanks in advance.

–Alex

Hi Alex,


Thanks for your inquiry. Please set the RowFormat.Height to 0 as shown below to get the required output. Please let us know if you have any more queries.

//Set
row height for image row - first row
<o:p></o:p>

imgRow.RowFormat.HeightRule = HeightRule.Exactly;

imgRow.RowFormat.Height = dImgShapeHeight;

//Start next row with image captions

Cell imgCell3 = builder.InsertCell();

builder.Write(sText1);

Cell imgCell4 = builder.InsertCell();

builder.Write(sText2);

titleRow = builder.EndRow();

//Set row height rule for the second row

titleRow.RowFormat.HeightRule = HeightRule.Auto;

titleRow.RowFormat.Height = 0;

builder.EndTable();

tbImage.AutoFit(AutoFitBehavior.FixedColumnWidths);

dDoc.Save(MyDir + "Out.docx");

dDoc.Save(MyDir + "Out.pdf");

Hi Tahir,
I just edited my code adding suggested set to zero.
Unfortunately I 'm getting the same result in PDF.
Would it be helpful if I create a sample without images - just 2 rows and send it to you for recreation of the problem?
Thanks,

–Alex

Hi Alex,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document
  • Please attach the output Word file that shows the undesired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we'll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

Hi Tahir,
As you requested, attached is a console application that is simplified to the point that explicitly shows the problem.
It performs the following steps:
a. Load empty InitialEmpty.docx file into the Document (file is located in \bin\Debug directory)
b. Create the table with 2 rows and 2 cells in each row and add some text to each cell
c. Set the height rule for the first row to HeightRule.Exactly and actual height to 200 points
d. Set the height rule for the second row to HeightRule.Auto.
e. Save document as _Result.docx in bin\Debug directory
f. Save document as _Result.pdf in bin\Debug directory

Run console application.
Please open _Result.docx in MS Word and you will see that the first row in the table has height 200 points and the second row is automatically adjusted to the height of the text - Expected result.
Please open _Result.pdf in Adobe Acrobat Reader and you will see that the second row height is not adjusted to the text. It picks up the height of the first row. - Unexpected result

I hope that will help you to find the problem.
Regards,

–Alex

Hi Alex,

Thanks for sharing the detail. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-13260. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

As a workaround of this issue, please set titleRow.RowFormat.Height to 0. Please check following highlighted code snippet.

Table tbImage = null;

Row imgRow;

Row titleRow;

Document dDoc = new Document(MyDir + "InitialEmpty.docx");

DocumentBuilder builder = new DocumentBuilder(dDoc);

//Start table

tbImage = builder.StartTable();

//Set cell width to 200 points

builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(200);

//Create Cell 1 of 2 in the first row

Cell imgCell1 = builder.InsertCell();

builder.Write("Cell #1 of the first row." + "\n\n\n" + "The height rule for this row is set to HeightRule.Exactly and Height is set to 200 points");

//Create Cell 2 of 2 in the first row

Cell imgCell2 = builder.InsertCell();

builder.Write("Cell #2 of the first row");

imgRow = builder.EndRow();

//Set row height for the first row using height rule "Exactly" !!!!!!!!!!!!!!

imgRow.RowFormat.HeightRule = HeightRule.Exactly;

imgRow.RowFormat.Height = 150;

//Start second row

//Create Cell 1 of 2 in the second row

Cell imgCell3 = builder.InsertCell();

builder.Write("Cell #1 of the second row." + "\n" + "The height rule for this row is set HeightRule.Auto");

//Create Cell 2 of 2 in the second row

Cell imgCell4 = builder.InsertCell();

builder.Write("This is the second cell of the second row");

titleRow = builder.EndRow();

//Set row height rule for the second row as "Auto" !!!!!!!!!!!!!!!

titleRow.RowFormat.HeightRule = HeightRule.Auto;

titleRow.RowFormat.Height = 0;

builder.EndTable();

tbImage.AutoFit(AutoFitBehavior.FixedColumnWidths);

dDoc.Save(MyDir + "_Result.docx", SaveFormat.Docx);

dDoc.Save(MyDir + "_Result.pdf", SaveFormat.Pdf);

The issues you have found earlier (filed as WORDSNET-13260) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.