Free Support Forum - aspose.com

Setting the header/footer details in page 2 only

Hi,

I have a requirement to be able to insert text into the header and footer of Page 2 only of a document. I have tried using the following code but the result is every even page contains the header footer details

documentTxt.MoveToHeaderFooter(HeaderFooterType.FooterEven);
currentSection.HeadersFooters.LinkToPrevious(false);
pageSetup.OddAndEvenPagesHeaderFooter = true;

Is there a way whereby I just update the page two header/footer details please

Hi Timothy,


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document where you want to set text in header and footer
  • Your expected document which shows the correct output. Please create this document using Microsoft Word application.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you code to achieve the same using Aspose.Words. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

HI

Please find attached a zipped file containing the following files

FX150812101621530000000000024433L25-header Details only on page 2 - this is what is produced by interfaceing to MS Word, and also what we want when using ASPOSE.

FX150812101621530000000000024433L25.Header on all even pages - This is what is produced by calling ASPOSE. As you can see we get the banding details on all even pages. This is not want we want.

Many thanks

Tim

Hi Timothy,


Thanks for the additional information.

Regarding “FX150812101621530000000000024433L25.Header on all even pages.doc”, this document has three Sections such that Section 1 has one page, Section 2 has one page and Section 3 has remaining four pages. You can create such document using following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Section 1 content...");

builder.MoveToHeaderFooter(HeaderFooterType.FooterEven);

builder.Write("This footer content is on all even pages of document");

builder.PageSetup.OddAndEvenPagesHeaderFooter = true;

builder.MoveToDocumentEnd();

builder.InsertBreak(BreakType.SectionBreakNewPage);

builder.Write("Section 2 content...");

builder.InsertBreak(BreakType.SectionBreakNewPage);

builder.Write("Section 3 Page 1 content...");

builder.InsertBreak(BreakType.PageBreak);

builder.Write("Section 3 Page 2 content...");

builder.InsertBreak(BreakType.PageBreak);

builder.Write("Section 3 Page 3 content...");

builder.InsertBreak(BreakType.PageBreak);

builder.Write("Section 3 Page 4 content...");

doc.Save(MyDir + @“15.7.0.docx”);


Regarding “FX150812101621530000000000024433L25-header Details only on page 2.doc”, this document has four Sections such that Section 1 has one page, Section 2 has one page, Section 3 has three pages and Section 4 is on the same last page. You can create such document using following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Section 1 content...");

builder.InsertBreak(BreakType.SectionBreakNewPage);

builder.Write("Section 2 content...");

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.Write("This Header content is only on Second page of document");

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

builder.Write("This Footer content is only on Second page of document");

builder.MoveToDocumentEnd();

builder.InsertBreak(BreakType.SectionBreakNewPage);

builder.CurrentSection.HeadersFooters.LinkToPrevious(false);

builder.Write("Section 3 Page 1 content...");

builder.InsertBreak(BreakType.PageBreak);

builder.Write("Section 3 Page 2 content...");

builder.InsertBreak(BreakType.PageBreak);

builder.Write("Section 3 Page 3 content...");

builder.InsertBreak(BreakType.SectionBreakContinuous);

doc.Save(MyDir + @“15.7.0.docx”);


I hope, this helps.

Best regards,

Morning

Many thanks for info but I think I might have a problem. My program is a DLL called by another program. The calling program using ASPOSE word to perform a merge and once complete passes the merged document it to my dll to basically remove empty rows in tables and insert the branding details into the header and footer, on page one for none visualy impaired customer and page 2 for visually impaired customers. The code provided inserts a sectionBreakNewPage and a PageBreak which I think will cause additional blank pages to be inserted into the document which I cant do. I will try the code later today and let you know the results.

Morning,

I tried using some of the code and basically it inserted an additional page break at the start of the document, it throw an exception when it tried

builder.InsertBreak(BreakType.SectionBreakNewPage);<?xml:namespace prefix = u1 /><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

After moving to the primaryfooter and when I remove this line of code I got all pages bar page 1 with the header and footer populdated.

Hi Timothy,


Thanks for your inquiry. To ensure a timely and accurate response, it would be great if you please create a standalone runnable simple console application (source code without any compile time errors) 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 investigation into your issue and provide you more information. Also, please attach related resources (Word documents) here for testing.

Best regards,

Morning,

Please find attached zipped file containing:

1. Sample c# test program code which call a DLL and passes the merged word document for branding.

2. Sample c# DLL code which updates the document passed to insert the brandind details.

3. Copy of a merged MS Word document used as input to test program.

4. Copy of a XML file used as a input file to the test program.

5. Copy of the file produced by the DLL/Test program.

6. copy of the logo file used by the DLL.

You will need to update the test program to point to trhe folder where you have copied the xml and Input Document to before testing.

Many thanks

Tim

Hi Timothy,


Thanks for your inquiry. We are checking this scenario and will get back to you soon.

Best regards,

Hi Timothy,


Thanks for being patient. I checked your ‘Project’ using Aspose.Words 15.7.0 and was unable to observe any issue i.e. no exception was produced on my end and there is no usage of DocumentBuilder.InsertBreak method in the entire solution. Also, to avoid new page break and to specify start of new section on the same page as the previous section, you can use BreakType.SectionBreakContinuous. Hope, this helps.

Best regards,

Morning,

Sorry dont understand what you are tellling me. We use ASPOSE 15.5.0.0. My DLL is passed a merged document and all I want to do is insert baranding details into the header and footer into page one if the variable VISUAL_IMPAIRMNT is set to 0 otherwise page 2 if not. If I insert a InsertBreak I create a new page which is not want I want to do. Can you please show me sample code used where you observed no issue. Are you saying we have to go to release 15.7.0.0.

Many thanks

Tim

Hi Timothy,


Thanks for your inquiry. Yes, please always use the latest version of Aspose.Words. Secondly, to ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document where you want to manipulate headers and footers
  • Your expected document which shows the correct output. Please create this document using Microsoft Word application.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you code to achieve the same using Aspose.Words. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

Morning

Please find attached a zipped file with containing the following documents

FX150812101621530000000000024433L25-Merged-InputFile.doc - This is the input file passed.

FX150812101621530000000000024433L25.Header on all even pages produced by ASPOSE.doc - This is the file produced by my DLL making calls to ASPOSE and which sample code was provided.

FX150812101621530000000000024433L25-header Details only on page 2 produced by MS Word - This is the file produced by making calls to MS Word libraries via a VB Script

Regards

Tim

Sorry forgot to attach zipped file

Regards

Tim

Hi Timothy,


Thanks for the additional information. Page 1 of your ‘FX150812101621530000000000024433L25-Merged-InputFile.doc’ document is actually the whole Section 1 while the Section 2 starts from Page 2. Page 3 and onward is Section 3. In this case, you can use the following code to get the desired output:

Document doc = new Document(MyDir + @“FX150812101621530000000000024433L25-Merged-InputFile.doc”);

DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Section sec in doc.Sections)

sec.ClearHeadersFooters();

builder.MoveToSection(1);

builder.CurrentSection.PageSetup.DifferentFirstPageHeaderFooter = true;

builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);

builder.Writeln("Page 2 content");

doc.Save(MyDir + @"15.7.0.docx");


I hope, this helps.

Best regards,

HI,

Sorry in delay getting back to you. Yes your solution worked. Thanks you very much for your time and help.

Regards

Tim