Free Support Forum - aspose.com

Manipulate Header Height

Hi, is it possible to modify the height of a header. Basically, I want to make it smaller than the default one. Specifically, I want a header of 13pts height. I use the following code snippet to initialize the header, but i haven’t found any API to set the height.

Paragraph headerParag = new Paragraph(docAspose);
headerParag.clearParaAttrs();
headerParag.clearRunAttrs();
ParagraphFormat pf = headerParag.getParagraphFormat();
pf.getStyle().getFont().setName(“Times New Roman”);
pf.getStyle().getFont().setSize(12);

HeaderFooter header = new HeaderFooter(docAspose,
HeaderFooterType.HEADER_FIRST);

header.appendChild(headerParag);
section.appendChild(header);

Hi Giorgos,


Thanks for your inquiry.

I think, in your case you can just decrease header distance (distance between top of page and header). In this case header will be moved up and there will be small gap between header and body. You can achieve this by using the following code:

Document doc = new Document(“c:\temp\x.docx”);


for (Section section : doc.getSections()){

section.getPageSetup().setHeaderDistance(13);

}


doc.save(“C:\Temp\out.docx”);

I hope, this helps.

Best regards,

Thanks very much for your reply. I have thought this work around but I would like to make the height of the header the same as the original document I want to construct. That means that I have to decrease the height of the footer. Is this possible?

Hi Giorgos,


Thanks for your inquiry. Sure, as per your needs, you can try set different combinations of values to the FooterDistance, HeaderDistance, TopMmargin, BottomMargin attributes of the PageSetup class. You can also use PageSetup.ClearFormatting method to reset page set-up to default paper size, margins and orientation.

Best regards,