We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Set different margin for header and footer

Hi,
I'm using syncfusion pdf for asp.net core.
I need to set no margin for header and footer and I need to set right and left margin for the rest of the page.
Any suggestion?
Thanks 



9 Replies

SL Sowmiya Loganathan Syncfusion Team October 10, 2019 01:49 PM UTC

Hi Mini, 

Thank you for contacting Syncfusion support.  

We have created the workaround sample to achieve your requirement. Please find the sample for the same from below, 

Please try the above sample in your end and let us know if is satisfies your requirement.  

Regards, 
Sowmiya Loganathan 




MD Mini Dev October 24, 2019 02:21 PM UTC

Hi, thanks for the answer.
My mistake was this:
compositeField.Draw(footer.Graphics);
instead  of
compositeField.Draw(footer.Graphics, new PointF(470, 40));

You pass the location as argument. How can I pass the correct location? Why do you pass 470 as x and 40 as y and not another value?


PV Prakash Viswanathan Syncfusion Team October 25, 2019 11:26 AM UTC

Hi Mini, 

Thank you for the update.  

We need to specify the location to draw the composite field. So, that it will be rendered in the provided location. We provided the this (470, 40) location to draw the composite field in bottom right corner in the footer template. Here the footer template width is page width and the footer template height is 50. So, we provided 470, 40 in the sample. We can specify the location value based on the requirement.  

Please let us know if you need any further assistance on this.  

Regards, 
Prakash V 



MD Mini Dev October 25, 2019 01:09 PM UTC

Hi,
I tried but I get the footer cutted off.

The code:

public class PdfBuilder
{
    private PdfDocument _document;
    
    private float _pageWidth => _document.Pages[0].GetClientSize().Width;
    private float _pageHeight => _document.Pages[0].GetClientSize().Height;

    public PdfBuilder()
    {
        _document = new PdfDocument();
    }

    public void SetMargin(float top, float left, float bottom, float right)
    {
        _document.PageSettings.Margins.Top = top;
        _document.PageSettings.Margins.Left = left;
        _document.PageSettings.Margins.Right = bottom;
        _document.PageSettings.Margins.Bottom = right;
    }
    public void AddPageToDocument()
    {                                   
        //Add a page to the document
        _document.Pages.Add();            
    }
    public void AddFooter()
    {
        RectangleF rect = new RectangleF(0, 0, _pageWidth, 50);
        //Create a Page template that can be used as footer.            
        PdfPageTemplateElement footer = new PdfPageTemplateElement(rect);
        PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
        PdfBrush brush = new PdfSolidBrush(Color.Black);
        //Create page number field.
        PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);
        //Create page count field.
        PdfPageCountField count = new PdfPageCountField(font, brush);
        //Add the fields in composite fields.            
        PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Copyright " + DateTime.Now.Year + " This the company name " + DateTime.Now.ToLongDateString() + "this the website - Pag. {0} / {1}", pageNumber, count);
        compositeField.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
        compositeField.Bounds = footer.Bounds;
        //Draw the composite field in footer.
        compositeField.Draw(footer.Graphics, new PointF(0, 45));
        //Add the footer template at the bottom.
        _document.Template.Bottom = footer;

    }
}

Where am I doing wrong?


GK Gowthamraj Kumar Syncfusion Team October 28, 2019 11:12 AM UTC

Hi Mini, 

Thank you for your update. 

We have checked the conversion with provided details, the footer has clipped within bound height. We have modified the bounds into (0, 35) , then draw a footer properly inside the pdf page. Please try the conversion with below solution and let us know the result. 

//Draw the composite field in footer 
compositeField.Draw(footer.Graphics, new PointF(0, 35)); 

Please let us know if you need any further assistance on this. 

Regards, 
Gowthamraj K 



MD Mini Dev November 4, 2019 02:01 PM UTC

If I write
//Draw the composite field in footer 
compositeField.Draw(footer.Graphics, new PointF(0, 35)); 

It draw the footer with the margin set. I need to draw the footer outside the default margin. 


SL Sowmiya Loganathan Syncfusion Team November 5, 2019 01:11 PM UTC

Hi Mini, 

While adding footer to PDF document, it will draw only in inside of the PDF margin. So we cannot able to draw the footer in outside of the margin. Please refer the below KB for more details, 

Please let us know if you have any concerns on this.  

Regards, 
Sowmiya Loganathan 



MD Mini Dev November 6, 2019 09:38 AM UTC

So I can't set no margin for header and footer while adding them to pdf document, is this right?
I need to do something like 
So how can I do to set no margin for header and footer in a pdf document?
Is it possible?
Thanks


SL Sowmiya Loganathan Syncfusion Team November 7, 2019 12:12 PM UTC


Hi Mini, 

At present we do not have support to set no margin to header and footer and set right and left margin to rest of pages in PDF document. As we said earlier as a workaround only we can achieve your requirement using the sample provided by you in the previous update.  

Please let us know if you need any further assistance on this.  

Regards, 
Sowmiya Loganathan 


Loader.
Live Chat Icon For mobile
Up arrow icon