Header footer size

Hi,


I using Aspose 11.0.0 java version.

I trying out the HeaderFooter class.

I am com.aspose.pdf classes
  • I found out that the height of this section cannot be changed. Is it really fixed ?
  • What would I have to do to add 2 headers on the first PDF page? OR 2 footer on the last page ?
I am trying to avoid stamping of elements as my application generates 1000’s of pages of PDF.



Hi Saurabh,


The Header object is rendered inside Top margin of page and Footer is rendered inside bottom margin of page. However in case you need to display two Headers/Footers on particular page, you may consider adding Table object inside Header/Footer area, where you can display intended header/footer contents inside table rows.

In case of any further query, please feel free to contact.

Hi,


Your solution is fine but I have another problem now.
I am using following code to insert a text at a absolute position in header.

public static void main(String[] args) {
long start = System.currentTimeMillis();
Document doc = new Document();
doc.setFitWindow(true);
doc.setCenterWindow(true);

Page page = doc.getPages().add();
page.getPageInfo().setHeight( PageSize.getA4().getHeight() );
page.getPageInfo().setWidth( PageSize.getA4().getWidth() );
MarginInfo info = new MarginInfo( 0, 0, 0, 150 );
page.getPageInfo().setMargin( info );
FloatingBox hf = new FloatingBox( 100, 50 );
hf.setLeft( 0 );
hf.setTop( 5 );
hf.setBorder( new BorderInfo( BorderSide.All, Color.getBlue() ) );
hf.getParagraphs().add( new TextFragment( “Sample text” ) );
HeaderFooter h1 = new HeaderFooter();
h1.getParagraphs().add( hf );
page.setHeader( h1 );
doc.save( path );
long end = System.currentTimeMillis();
System.out.println("Generating took "+(end - start));
System.out.println(“Generation complete”);
}

But there is one problem I am not able to set hf.setLeft( 0 );
There is always a gap there.

I am not to understand what is causing the gap there ?

I even set the margin to zero still there is a gap.
I have attached a image to explain what I am trying to achieve.

Hi Saurabh,

Thanks for your inquriy. You need to set HeaderFooter margin as following to control position of Floatingbox in page header, it will help you to accomplish the task.

com.aspose.pdf.HeaderFooter h1 = new com.aspose.pdf.HeaderFooter();

h1.getMargin().setLeft(0);

h1.getParagraphs().add( hf );

Please feel free to contact us for any further assistance.

Best Regards,

@tilal.ahmad, Hi !
Am also stuck in somewhat a similar issue, that is, I want to set the left and right space of the footer to be nil, that is footer should leave no space on the left and right hand side.
I tried h1.getMargin().setLeft(0); and achieved it for the left hand side, but for the RIGHT , am facing problem.
I am attaching the screenshot for your reference, please help me with the same. Footer.PNG (4.8 KB)

NOTE : I tried h1.getMargin().setRight(0); BUT, It is removing the entire last column from the footer, when i am setting SetRight(80f), am getting the last column, but again its not covering the entire page, ultimately what I need to achieve.

Please Help !

@tilal.ahmad, I did it !
But , now when I have achieved the proper margins, am not getting the value in the last column.
Please see this screenshot Footer1.PNG (4.1 KB)

I have used this piece of code :
footer.getMargin().setLeft(15.0);
footer.getMargin().setRight(20.0);

Please Help me resolve this

@Kushal.20

We have replied similar concerns about footer on page width in another thread of yours. In case this issue is a different one, then please create a separate post along with all the details so that we may investigate further to help you out.