@nipunjain1964
Can we have two headers for a doc, one is HeaderFirst and another is HeaderPrimary.
Yes, we can have different Headers in a Word document. We can achieve this, by dividing the document into multiple sections and using the different HeaderFooterType
for each section.
Our requirement is to have no header and footer for the first page. Rest of the pages can have header and footer.
Following example explains how you can do this:
Use PUT /words/{name}/{sectionPath}/headersfooters API and set following values of the parameters:
name = DifferentHeaders.docx
headerFooterType = “HeaderPrimary” (Note the double quotes)
sectionPath = sections/1
You should get following response:
{
"HeaderFooter": {
"Paragraphs": {
"link": {
"Href": "http://api.aspose.cloud/v1.1/words/DifferentHeaders.docx/sections/1/headersfooters/0/paragraphs",
"Rel": "self",
"Type": null,
"Title": null
}
},
"DrawingObjects": {
"link": {
"Href": "http://api.aspose.cloud/v1.1/words/DifferentHeaders.docx/sections/1/headersfooters/0/drawingObjects",
"Rel": "self",
"Type": null,
"Title": null
}
},
"Type": "HeaderPrimary",
"link": {
"Href": "http://api.aspose.cloud/v1.1/words/DifferentHeaders.docx/sections/1/headersfooters/0",
"Rel": "self",
"Type": null,
"Title": null
}
},
"Code": 200,
"Status": "OK"
}
Then call PUT /words/{name}/{paragraphPath}/runs API, and set following values of the parameters:
name = DifferentHeaders.docx
paragraphPath = sections/1/headersfooters/0/paragraphs/0
run = { “Text”: “First!” }
You should get following API response:
{
"Run": {
"Text": "First!",
"NodeId": "1.0.0.0",
"link": {
"Href": "http://api.aspose.cloud/v1.1/words/DifferentHeaders.docx/sections/1/headersfooters/0/paragraphs/0/runs/0",
"Rel": "self",
"Type": null,
"Title": null
}
},
"Code": 200,
"Status": "OK"
}
Now, download the output Word document from Aspose Cloud Dashboard. The output document have no header on the first page but all other pages have a header.
Input Document: DifferentHeaders.zip (13.4 KB)
Output Document: DifferentHeaders_Output.docx.zip (18.0 KB)
We hope this helps!