Aspose.Word- Append word document and Issues in styles and extra page break

Hi team,

I am using Aspose.words, I want to append word document in document builder.
I have attached the sample code which I used to achieving same.

The issues are:-

  1. Page break inserted BEFORE appending word document.
  2. Heading styles are not applied properly AFTER appending word document.

Feel free to ask for more details.

Thanks and Regards
Nakul

Hello
Thanks for your request.

  1. In this case you should you should just specify section start Continuous. See the following snippet of code:
Aspose.Words.Document sourceDocument = new Aspose.Words.Document(documentStream, new Aspose.Words.LoadOptions(Aspose.Words.LoadFormat.Docx, "", ""));
sourceDocument.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
sourceDocument.FirstSection.HeadersFooters.LinkToPrevious(true);
  1. Could you please be more specific regarding the problem with Heading styles? As I can see the output looks fine.

Best regards,

Thanks Andrey,

  1. This issue is solved I added the marked code, it is working.
  2. You can refer the attached code for it…

Line 32:

InsertWordDocumentAtEnd(File.ReadAllBytes(@"Input\Testword.docx"));

Which appends word document at end.

Line 36:

InsertHeadings("Heading 1", HeadingLevel.Heading1);

Adds a Heading "Heading 1"with style Heading 1
which should have font
Line 93:

ProcessingDocumentBuilder.Font.Name = "Cambria";

But font displayed in document is “Calibri” (You can see the out put file in attached “FinalReprt.docx”, produced by the code in previous post)

This happens only AFTER word document is appended in main document.

Please help.

Thanks and Regards
Nakul

Hello
Thank you for additional information. In this case you should just add the one line of code:

public static void SetTextFormat(HeadingLevel headingLevel)
    {
        ParagraphFormat paragraphFormat = ProcessingDocumentBuilder.ParagraphFormat;
        paragraphFormat.ClearFormatting();
        ProcessingDocumentBuilder.Font.ClearFormatting();

Best regards,

Thanks Andrey,

It is working perfectly now.

Regards
Nakul