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

Free Support Forum - aspose.com

Header footer cannot link to previous


my document has three sections, and i want to create headerfooter for them, my strategy is write some custome text in header & footer in the section one , and other sections will link to previous.

but the problem is: only first section's header & footer render normally other section's header has lost something(text disappeared) but footer is ok.


private void CreateHeaderFooter(ADoc.Document docx){
double headerDistance = ADoc.ConvertUtil.MillimeterToPoint(1.5 * 10);
double footerDistance = ADoc.ConvertUtil.MillimeterToPoint(1.0 * 10);
// make all of the section has same headerfooter distance
foreach (ADoc.Section sec in docx.Sections) {
sec.PageSetup.HeaderDistance = headerDistance;
sec.PageSetup.FooterDistance = footerDistance;
}
// generate first section's header footer
builder.MoveToDocumentStart();
ADoc.Section currentSection = builder.CurrentSection;
ADoc.PageSetup ps = currentSection.PageSetup;
BuildingHeader(docx, ps, ADoc.HeaderFooterType.HeaderPrimary);
BuildingHeader(docx, ps, ADoc.HeaderFooterType.HeaderFirst);
BuildingHeader(docx, ps, ADoc.HeaderFooterType.HeaderEven);
BuildingFooter(docx, ps, ADoc.HeaderFooterType.FooterPrimary);
BuildingFooter(docx, ps, ADoc.HeaderFooterType.FooterFirst);
BuildingFooter(docx, ps, ADoc.HeaderFooterType.FooterEven);
// make other section link to first section' header footer
if (docx.Sections.Count > 1) {
for (int i = 1; i < docx.Sections.Count; i++) {
//docx.Sections[i].HeadersFooters.LinkToPrevious(true);
docx.Sections[i].ClearHeadersFooters();
}
}
}

private void BuildingHeader(ADoc.Document docx, ADoc.PageSetup ps, ADoc.HeaderFooterType hfType) {
builder.MoveToHeaderFooter(hfType);
builder.Write("test header");
}

private void BuildingFooter(ADoc.Document docx, ADoc.PageSetup ps, ADoc.HeaderFooterType hfType) {
builder.MoveToHeaderFooter(hfType);
builder.Write("test footer");
}

please see the attachment for further testing.

in use 14.2

thanks.

something additional information:

in my attachment there has two file, one is the source file, another one with the name contains "_out" is output file after adding the header & footer.

Hi Pyntia,


Thanks for your inquiry. I produced an output document (see attached out.docx) from your “Test.docx” by executing your code on my side. All pages are showing header/footer information correctly. I could not see any issue with this output document, could you please clarify where the issue is?

Secondly, it would be great if you please create a standalone runnable simple console application that helps us reproduce your problem on our end and attach it here for testing. As soon as you get this simple application ready, we’ll start further investigation into your issue and provide you more information.

Best regards,

hi, Awais


thank you for your reply

your attachment is really correctly, it is strange thing.
in my computer, it render like below picture:

lost header

i will check my application later, can you please share me your test code?
thanks

hi


i have been reproduced the scenario, please see the attachment which contains standalone app for further testing.

the reason is InsertWatermarkText function, if comment this function, the result will be ok.

please check for it. thanks

Hi Pyntia,


Thanks for the additional information. In this case, simply calling “InsertWatermarkText” method before “CreateHeaderFooter” method resolves this issue.

Best regards,

hi, Awais


i know this workaround method, however, is it mandatory need calling watermark api first if i want to insert watermark?

Hi Pyntia,

For the moment, you can call watermark API first as it works in this case. We will further investigate your code and let you know.

Best Regards,

hi, Muhammad


thank you for your reply

i will be waiting for the result.
Hi Pyntia,

Thanks for your inquiry.
Pyntia:
i know this workaround method, however, is it mandatory need calling watermark api first if i want to insert watermark?
Yes. When you call watermark code, the "InsertWatermarkIntoHeader" method creates HeaderPrimary, HeaderFirst and HeaderEven in each section from scratch. It ensures that all three headers contain only one paragraph with the watermark shape.

So, there is no need to call "CreateHeaderFooter" method first because "InsertWatermarkIntoHeader" method will re-create these headers again.

Best regards,

hi, Awais


i got it and thank you for your explain.