Free Support Forum - aspose.com

Copying Headers and Footers

I have a document that I generate on the fly and at the end I need to insert print fields into the first page header. As the document was being built there were no first page headers, so if I create a first page header, it is blank. Is there a way to copy all of the text/formatting/images from the main header and put it into the first page header, so I do not lose this information?

Hi,

Thank you for interest in Aspose.Word.

Sorry it seems I don’t fully understand your problem. You can insert content into the first page header at any time by calling builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst). Please specify what obstacles are you facing with, probably post a snippet of your code.

Basically, I am building one large document by combining many small documents together. Some of the pages within the document need to be printed duplex short and some need to be simplex. I can accomplish this by using print fields in the first page header of the section. When I am combining the documents together, the documents only contain a single header (i.e. no first page header). When I get an instruction (from an outside source) that states the current section needs to be printed duplex, I need to basically add a first page header to the section which looks the same as main header for that section, except for the print field that I am adding. So this is the code that I am using:


'lngSection is a section that needs to be modified
m_ADocBuilder.MoveToSection(lngSection)
m_ADocBuilder.Document.Sections(lngSection).PageSetup.DifferentFirstPageHeaderFooter = True
m_ADocBuilder.MoveToHeaderFooter(AWord.HeaderFooterType.HeaderFirst)
m_ADocBuilder.InsertField(“PRINT 27"”&l1S""", “”)
'Here is where I would want to copy the content from the main header to the first page header

Thanks for the further explanation. Unfortunately, I have to disappoint you. Copying content from one header to another is not possible at the moment, but will be supported in the future.

Thanks Dmitry. That is disappointing that this cannot be accomplished at this time, but is it possible to put it in as an enhancement request? We have decided that we will still use the Aspose Word product, we will just have to utilize Word after Aspose finishes the document to tackle our header and printing issues. Once you have those two things implemented we can totally remove Word from the equation.

Thanks,

John

Sure, your problem will be certainly resolved as soon as we implement the new object model we are working on. We have also logged your request separately.