Section heading indented and TOC is not aligned after save to PDF

hi team, i have a problem.

when i save the doc as pdf after merging multiple documents, some of the section’s heading is indented.
and also the table of content is not aligned after saving to pdf.
if i save it as docx its ok.
please help me, my client’s company have a license for the Aspose Words.

this is the generated docx
heading_docx.png (9.8 KB)
toc_docx.png (7.9 KB)

this is the generated pdf
heading_pdf.png (41.0 KB)
toc_pdf.png (17.7 KB)

this is the sample project
AsposeBug.zip (1.8 MB)

@widi

We have saved the document (after mail merge DOCX) to PDF using the latest version of Aspose.Words for .NET 19.7 and have not found the shared issue.

You have shared your complete project. Could you please share the simplified code example to reproduce this issue at our end? We will investigate this issue and provide you more information about your query.

the code that i share is the simplified project,
please just take a look of it,
its really simple and easy to understand.

another problem is the background image in the pdf is supposed to fill the whole page,
but its some kinda shifted, so there is a white area on the edge of the page.
its not happening if i save it as docx, its only happening when i save it as pdf.

btw im not using mail merge, im inserting the section’s documents during replace.
here is the tags in the main document that will be replaced by each section’s document:

[merge]01-rating_summary[/merge]
[merge]02-outcomes_snapshot[/merge]
[merge]03-executive_summary[/merge]
[merge]04-growth_metrics[/merge]
[merge]05-investment[/merge]
[merge]06-fees_charges[/merge]

and this is the replacing code:

private static void MergeSections(Document doc, DocDataModel data)
{
foreach (var document in data.DocumentDataList)
{
var options = new FindReplaceOptions
{
ReplacingCallback = new MergeSectionsCallback(document.FilePath)
};

doc.Range.Replace("[merge]" + document.ID + “[/merge]”, “”, options);
}
}

private class MergeSectionsCallback : IReplacingCallback
{
private readonly string _filePath;

public MergeSectionsCallback(string filePath)
{
_filePath = filePath;
}

ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
var docToInsert = new Document(_filePath);
var builder = new DocumentBuilder((Document)e.MatchNode.Document);
builder.MoveTo(e.MatchNode);
builder.InsertDocument(docToInsert, ImportFormatMode.KeepSourceFormatting);
e.Replacement = “”;
return ReplaceAction.Replace;
}
}

@widi

Please spare us some time. We will check your project and investigate the issue. We will get back to you soon.

@widi

We have logged this issue as WORDSNET-18905 in our issue tracking system.

This issue has been logged as WORDSNET-18906.

We apologize for your inconvenience.

Please note that Aspose.Words mimics the behavior of MS Word. If you convert your final DOCX to PDF using MS Word, you will get the same output.

@widi

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-18906) as ‘Not a Bug’.

Please note that Aspose.Words mimics the behavior of MS Word. If you convert your final DOCX to PDF using MS Word, you will get the same output.

@widi

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-18905) as ‘Not a Bug’.

We suggest you please check the detail of Range.Replace method. Aspose.Words uses metacharcters on find/replace like MS Word.

The AppendLine method produces “CLRF” character. So, please replace following foreach loop in MergeSections method

foreach (var item in data.DocumentDataList)
  sectionTags.AppendLine($@"{ReportTag.MergeOpen}{item.ID}{ReportTag.MergeClose}");

With

foreach (var item in data.DocumentDataList)
  sectionTags.Append($@"{ReportTag.MergeOpen}{item.ID}{ReportTag.MergeClose}&p");

This will fix the indention problematic with text.