Footer not visible after merging Word and PDF documents

Hello Team ,

Footer got disappear after merging multiple documents by using aspose lib ,
Please check attach code and documents for more details .
You help is appreciated
Footer Dissapaer Issue.zip (232.5 KB)

Thanks,Avinash

@Chilke

Issue Summary

You are merging several Word and PDF files with Aspose libraries and the footer disappears after the merge operation.

Typical Causes

Cause Why it removes the footer How to fix
Using ImportFormatMode.UseDestinationStyles when appending documents The destination document’s style/section settings overwrite the source footers. Use ImportFormatMode.KeepSourceFormatting.
Merging PDF → Word by simply loading the PDF Aspose.Words treats the PDF as a single section without preserving the original footers. Convert the PDF to a Word document first (e.g., Aspose.Pdf.Facades.PdfConverter or Aspose.Words.Document(pdfStream)) and then append.
Footers defined only on the first page / odd‑even The merged document may create a new section where those special footer settings are lost. Ensure all sections have the required footer type (Primary, First, Even).
Using DocumentBuilder.InsertDocument without the proper ImportFormatMode Similar to the first case – source footer styles are ignored. Pass ImportFormatMode.KeepSourceFormatting to InsertDocument.

Recommended Approach (C# / .NET)

Below is a robust pattern that works for Word + PDF merges while preserving every footer.

using Aspose.Words;
using Aspose.Pdf.Facades;

// ---------------------------------------------------
// 1. Load the first Word document (acts as the destination)
// ---------------------------------------------------
Document finalDoc = new Document("Doc1.docx");

// ---------------------------------------------------
// 2. Append additional Word documents
// ---------------------------------------------------
string[] wordFiles = { "Doc2.docx", "Doc3.docx" };
foreach (var file in wordFiles)
{
    Document src = new Document(file);
    // Keep the source formatting (including footers)
    finalDoc.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);
}

// ---------------------------------------------------
// 3. Convert each PDF to a temporary Word document
// ---------------------------------------------------
string[] pdfFiles = { "FileA.pdf", "FileB.pdf" };
foreach (var pdf in pdfFiles)
{
    // Convert PDF → DOCX in memory
    using (MemoryStream pdfStream = new MemoryStream(File.ReadAllBytes(pdf)))
    using (MemoryStream docxStream = new MemoryStream())
    {
        // PDF → DOCX conversion (Aspose.PDF)
        PdfConverter converter = new PdfConverter();
        converter.BindPdf(pdfStream);
        converter.DoConvert();
        converter.SaveAsDocX(docxStream);
        converter.Close();

        // Load the converted DOCX
        docxStream.Position = 0;
        Document pdfAsDoc = new Document(docxStream);

        // Append to the final document preserving footers
        finalDoc.AppendDocument(pdfAsDoc, ImportFormatMode.KeepSourceFormatting);
    }
}

// ---------------------------------------------------
// 4. Save the merged result
// ---------------------------------------------------
finalDoc.Save("MergedResult.docx");

Key Points in the Code

  1. ImportFormatMode.KeepSourceFormatting – Guarantees the source footers (and other section settings) are retained.
  2. PDF conversion – Uses Aspose.Pdf.Facades.PdfConverter to turn each PDF into a Word document first, which ensures the PDF’s original footers (if any) are turned into Word footers that can be merged.
  3. Memory‑stream conversion – No intermediate files are required; everything stays in memory, producing a cleaner workflow.

Additional Checks

  • Footer Types – Verify that your original Word files contain the Primary footer (or the specific First Page / Even Page you need). After the merge, open the resulting document → Header & FooterEdit Footer to confirm the correct type is present.
  • Section Breaks – If you manually add section breaks after the merge, ensure they inherit the proper footer settings:
    foreach (Section sec in finalDoc.Sections)
    {
        sec.Footers.LinkToPrevious(false); // keep each section's own footer
    }
    
  • Version Compatibility – The code above works with Aspose.Words 23.12+ and Aspose.PDF 23.12+. If you use an older version, consider upgrading to benefit from bug‑fixes related to footer handling during merges.

What to Provide If the Problem Persists

If you still experience missing footers after trying the steps above, please share the following (you can paste the relevant snippets instead of the whole zip):

  1. Exact code you are using for merging (including the method you call – AppendDocument, InsertDocument, DocumentBuilder, etc.).
  2. Aspose product versions (e.g., Aspose.Words for .NET 23.9 and Aspose.PDF for .NET 23.9).
  3. A small sample (2‑3 pages) of a Word file that contains the footer and a PDF file you are merging.
    You can host them on a public file‑sharing service and provide the links.
  4. Whether the footer is a simple text, page number field, or a complex table/shape.

With those details we can reproduce the issue and give a pinpoint solution.


Helpful Links

If you have any further questions or need clarification, feel free to reply with the requested details. We’re happy to help!

@Chilke This occurs because in your code you unlink headers/footer in all sections of your input document. So inherited headers/footers are not shown in the output. You can try using LowCode method to merge your documents:

Aspose.Words.LowCode.Merger.Merge(@"C:\Temp\out.docx", new string[] { @"C:\Temp\Doc1.docx", @"C:\Temp\Doc2.pdf" });

out.docx (34.1 KB)

Or unlink headers/footers only in the first section:

Document doc1 = new Document(@"C:\Temp\Doc1.docx");
Document doc2 = new Document(@"C:\Temp\Doc2.pdf");

// Unlink headers/footer only in the first section.
doc1.FirstSection.HeadersFooters.LinkToPrevious(false);
doc2.FirstSection.HeadersFooters.LinkToPrevious(false);

// Merge documents.
Document result = Aspose.Words.LowCode.Merger.Merge(new Document[] { doc1, doc2 }, MergeFormatMode.KeepSourceFormatting);

result.Save(@"C:\Temp\out.docx");

out.docx (40.1 KB)

Thanks @alexey.noskov and @Professionalize.Discourse
Merge Code is working fine
OutPutAfterPaggingPageno.Docx (40.4 KB)

, But Existing footer got removed when adding Page number to merged document , After third page footer (Written By________) got removed , Please provide code to add page number for merged document , without disturbing exiting footer text , Below code is using for adding page number .

public Document AddPageNumberAfterMergingDocs(Document doc)
    {
        if (doc == null || doc.Sections.Count == 0)
            return doc;

        int tocSectionIndex = -1;

        // Step 1: Find TOC section index
        foreach (Field field in doc.Range.Fields)
        {
            if (field.Type == FieldType.FieldTOC)
            {
                Section tocSection = (Section)field.Start.GetAncestor(NodeType.Section);
                tocSectionIndex = doc.Sections.IndexOf(tocSection);
                break;
            }
        }

        for (int i = 0; i < doc.Sections.Count; i++)
        {
            Section section = doc.Sections[i];

            // Step 2: Get or create footer
            HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterPrimary];
            if (footer == null)
            {
                footer = new HeaderFooter(doc, HeaderFooterType.FooterPrimary);
                section.HeadersFooters.Add(footer);
            }

            // Step 3: Check if footer has a page number field
            bool hasPageNumber = footer.Range.Fields.Any(f => f.Type == FieldType.FieldPage);

            if (!hasPageNumber)
            {
                // Add centered "Page X" paragraph
                Paragraph pageNumberPara = new Paragraph(doc);
                pageNumberPara.ParagraphFormat.Alignment = ParagraphAlignment.Center;
                pageNumberPara.ParagraphFormat.SpaceBefore = 6;

                // "Page " prefix + page number field
                pageNumberPara.AppendChild(new Run(doc, "Page "));
                pageNumberPara.AppendField(FieldType.FieldPage, true);

                footer.AppendChild(pageNumberPara);
            }
            else
            {
                // Optional: If already exists, update the field (forces refresh)
                foreach (Field f in footer.Range.Fields.Where(f => f.Type == FieldType.FieldPage))
                {
                    f.Update();
                }
            }

            // Step 4: Restart numbering at TOC section
            if (i == tocSectionIndex)
            {
                section.PageSetup.RestartPageNumbering = true;
                section.PageSetup.PageStartingNumber = 1;
            }
            else
            {
                section.PageSetup.RestartPageNumbering = false;
            }
        }

        // Step 5: Update all fields and layout
        doc.UpdateFields();
        doc.UpdatePageLayout();

        return doc;
    }

@Chilke The problem occurs because when a header or footer is linked to the previous section, it does not actually exist in the current section — it is null. When you create an empty header or footer in the section, it no longer uses the header or footer from the previous section. Keeping this in mind, please try modifying your code as follows:

// Step 2: Get or create footer
HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterPrimary];
HeaderFooter prevFooter = (i > 0) ? doc.Sections[i - 1].HeadersFooters[HeaderFooterType.FooterPrimary] : null;
if (footer == null)
{
    footer = prevFooter != null ? (HeaderFooter)prevFooter.Clone(true) : new HeaderFooter(doc, HeaderFooterType.FooterPrimary);
    section.HeadersFooters.Add(footer);
}

Thanks @alexey.noskov Code is keeping footer in document , but page number is not updated for other merged document , if it contain already page no , Please check attach data
DataFiles.zip (135.8 KB)

Thanks,
Avinash

@Chilke Page numbers in MS Word documents are represented with PAGE fields. In the appended PDF there is no PAGE field. There is simple text:

Thanks you @alexey.noskov , For quick response, your help is appreciated .

1 Like