Formatting Issue after convert word to pdf file

Hello Support

I am using aspose word mail merge feature.where word template contains good formatting ,but after mail merge and save as pdf there is some formatting issue.please check

source file: ACCI Certificate of Origin ChAFTA.docx
Output file: a8512d10-8b99-4a21-9497-5502f348e3df.pdf

Hi Manish,

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 document that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to 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.

please find sample code as AsposeSampleApp.part01,02,03,04.rar

sample input file: Test.DOCX
sample output file: output.docx

Issue highlight as:

Hi Manish,

Thanks for sharing the detail. Please note that Aspose.Words mimics the same behavior as MS Word does. If you add the rows to the table using MS Word after performing the mail merge, you will get the same output.

In your case, we suggest you following solution:

  1. Perform the mail merge.
  2. Calculate the height of empty area in the page using Aspose.Words.Layout APIs.
  3. Add one row to the table and set its RowFormat.HeightRule to Exactly.
  4. Set RowFormat.Height to the value calculated by Aspose.Words.Layout APIs.

Hope this helps you. Please let us know if you have any more queries.

Thanks for your help , can you send me API example.

Hi Manish,

Thanks for your inquiry. Please use following code example to get the distance between paragraph after table and footer of page and add a row after table. Hope this helps you. We have attached the input and output documents with this post for your kind reference.

Document doc = new Document(MyDir + "test.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
MarkHeaderFooterBoundaries(enumerator);
Table table = (Table)doc.FirstSection.Body.Tables[0];
Paragraph paragraph = (Paragraph)table.NextSibling;
var renderObject = collector.GetEntity(paragraph);
enumerator.Current = renderObject;
RectangleF location = enumerator.Rectangle;
// Add row to table
table.Rows.Add(table.LastRow.Clone(true));
foreach (Cell cell in table.LastRow.Cells)
{
    cell.RemoveAllChildren();
    cell.EnsureMinimum();
}
table.LastRow.RowFormat.HeightRule = HeightRule.Exactly;
table.LastRow.RowFormat.Height = footerposition - location.Y;
Aspose.Words.Saving.DocSaveOptions docOptions = new Aspose.Words.Saving.DocSaveOptions();
docOptions.SaveFormat = Aspose.Words.SaveFormat.Doc;
doc.Save(MyDir + "Out v16.12.0.doc", docOptions);
static double footerposition = 0;
public static double MarkHeaderFooterBoundaries(LayoutEnumerator enumerator)
{
    do
    {
        if (enumerator.MoveLastChild())
        {
            MarkHeaderFooterBoundaries(enumerator);
            enumerator.MoveParent();
        }
        if (enumerator.Type == LayoutEntityType.HeaderFooter)
        {
            if (enumerator.Kind.Equals("PRIMARYFOOTER"))
                footerposition = enumerator.Rectangle.Top;
        }
        // Stop after all elements on the page have been proceed.
        if (enumerator.Type == LayoutEntityType.Page)
            return 0;
    } while (enumerator.MovePrevious());
    return 0;
}

Thanks for your help

Issue yet not resolved

please find attachment provided code behaving differently.

Hi Manish,

Thanks for your inquiry. Please decrease the height of last row of table to get the desired output. Please replace following line of code

table.LastRow.RowFormat.Height = footerposition - location.Y;

with

table.LastRow.RowFormat.Height = footerposition - location.Y - 5;

to get the desired output. Hope this helps you.