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

Free Support Forum - aspose.com

Get and set footer text with table

Hi,

I open source document and make some modifications in it. Due to those modifications footer text will be gone. So i get footer text and set it again to concerned pages and save the document. So my destination document will have modifications as well as footer data properly.

The code i use for getting footer text is

HeaderFooterfooterPrimary;

foreach (Section section in doc){

footerPrimary = section.HeadersFooters[HeaderFooterType.FooterPrimary];

}

string primary = footerPrimary.GetText();

the code for setting footer text is

builder.MoveToHeaderFooter(

HeaderFooterType.FooterPrimary);

builder.Write(primary);

But now problem is source document contains table. But GetText() method is not fetching the table structure. It is fetching content of table as normal paragraph only. So if i try to set that footer which i got from gettext method then in destination document table is missing.

I am attatching source document with footer having table for your reference.PFA.

My destination documnet also should contain table data in footer.

Kindly tell me how can i get footer text from a documnet in such a way that table information also comes and how can i set footer text with table in another document.

I just want to know how to get and set footer text which contains a table. Destination document can be anything it can be another new documnet. My requirement is i want to get footer info present in attatched source document and set it to another document footer but table information should come properly.

Kindly reply ASAP....Thankyou in anticipation.

Hi,

Thanks for your inquiry. Please use the following code to achieve this:

//Open A document

Document docA = new Document(MyDir + @"Doc.doc");

DocumentBuilder builderA = new DocumentBuilder(docA);

//Open B document

Document docB = new Document(MyDir + @"Input+Document.doc");

//Loop through all sections in the B document

foreach (Section sectB in docB.Sections)

{

Section sectA = null;

int sectBIndex = docB.Sections.IndexOf(sectB);

//Check whether document A conteins section with same index

if (docA.Sections.Count > sectBIndex)

{

//Get correcponding section

sectA = docA.Sections[sectBIndex];

}

else

{

//Insert empty section

builderA.MoveToDocumentEnd();

builderA.InsertBreak(BreakType.SectionBreakContinuous);

sectA = builderA.CurrentSection;

}

//Loop throught all Headers/Footers in the B document

foreach (HeaderFooter hfB in sectB.HeadersFooters)

{

//Check whether current section from docA conteins

//Header/Footer with the same type as h/f from docB

if (sectA.HeadersFooters[hfB.HeaderFooterType] != null)

{

//Append content from h/f B to h/f A

foreach (Node childB in hfB.ChildNodes)

{

//Import node

Node childA = docA.ImportNode(childB, true, ImportFormatMode.KeepSourceFormatting);

//Appent node to h/f

sectA.HeadersFooters[hfB.HeaderFooterType].AppendChild(childA);

}

}

else

{

//Copy whole h/f

Node hfA = docA.ImportNode(hfB, true, ImportFormatMode.KeepSourceFormatting);

//Insert h/f

sectA.HeadersFooters.Add(hfA);

}

}

}

//Save output document

docA.Save(MyDir + @“out.doc”);


I hope, this helps.

Best regards,