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

Free Support Forum - aspose.com

Adding a footer to an appended document

Hi,

I'm trying to add some footer text to an appended document but am having no success. Here is the function I'm using. Can you please tell me why this is not working?

Thanks

public void AddDocument(string DocumentNameandPath, string FooterText)

{

if (String.IsNullOrEmpty(DocumentNameandPath))

throw new ArgumentException("DocumentNameandPath is null or empty.", "DocumentNameandPath");

// Open the source document.

Document srcDoc = new Document(DocumentNameandPath);

if (FooterText.Length > 0)

{

foreach (Section srcSection in srcDoc)

{

HeaderFooter Footer = srcSection.HeadersFooters[HeaderFooterType.FooterPrimary];

if (Footer == null)

{

Footer = new HeaderFooter(srcSection.Document, HeaderFooterType.FooterPrimary);

srcSection.HeadersFooters.Add(Footer);

}

}

srcDoc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].Range.Replace("*", FooterText, false, false);

}

mDocument.Document.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);

//AppendDoc(mDocument, srcDoc, FooterText);

}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please try using the following code:

public static void AddDocument(string DocumentNameandPath, string FooterText)

{

if (String.IsNullOrEmpty(DocumentNameandPath))

throw new ArgumentException("DocumentNameandPath is null or empty.", "DocumentNameandPath");

// Open the source document.

Document srcDoc = new Document(DocumentNameandPath);

DocumentBuilder builder = new DocumentBuilder(srcDoc);

if (FooterText.Length > 0)

{

for (int sectIdx=0; sectIdx<srcDoc.Sections.Count; sectIdx++)

{

//move documentbuilder cursor to the current section

builder.MoveToSection(sectIdx);

//move documentbuilder cursor to the footer

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

//Insert text into teh footer

builder.Write(FooterText);

}

}

mDocument.Document.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);

}

Also see teh following link to learn how to insert header/footer into the document:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/moving-to-a-headerfooter.html

Best regards.