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

How to display header only on first page when previewing

Hi..
I am using GroupingGridPrintDocumentAdv to print a gridgroupingcontrol with a header and footer, how can i display the header only on first page.
The only property related to header is GroupingGridPrintDocumentAdv.HeaderHeight..any help??

7 Replies

AR Amal Raj U Syncfusion Team November 18, 2016 07:18 AM UTC

Hi Hussain, 

Thanks for using Syncfusion products. 

In order to avoid displaying the Header only in the first page, then DrawGridPrintHeader event can be used. Please make use of the below code, 
 
Code Example 
//Event Subscription. 
printDocument.DrawGridPrintHeader += new GridPrintDocumentAdv.DrawGridHeaderFooterEventHandler(printDocument_DrawGridPrintHeader); 
 
void printDocument_DrawGridPrintHeader(object sender, GridPrintHeaderFooterTemplateArgs e) 
    if (e.PageNumber > 1) 
    { 
        //To avoid Headers in pages other than first page. 
        e.Cancel = true
    } 
 
Sample Link 
 
Regards, 
Amal Raj U. 



HU Hussain November 20, 2016 09:17 AM UTC

Hi Amal,

Thank you for answering.

i want to display header only on then first page. I managed to display it only on first page either by making GroupingGridPrintDocumentAdv.HeaderHeight = 0, or by removing the handler of GroupingGridPrintDocumentAdv.DrawGridPrintHeader, but the header place is still reserved as shown in the file i attached.what i want is to make the grid in the second page fills the hole page excepting the footer place.

Note: i am using vb.net



Attachment: header_1eb9bc4b.rar


AR Amal Raj U Syncfusion Team November 21, 2016 12:22 PM UTC

Hi Hussain, 

Thanks for the update. 

The header space for the pages other than first page can be removed by removing the allotted margins for the headers to the page. Please make use of the below code, 

Code Example 
void printDocument_DrawGridPrintHeader(object sender, GridPrintHeaderFooterTemplateArgs e) 
    if (e.PageNumber == 1) 
        firstPagePrinted = true
    else 
    { 
        //To avoid Headers in pages other than first page. 
        e.Cancel = true
    }            

void printDocument_PrintPage(object sender, PrintPageEventArgs e) 
    if (firstPagePrinted) 
        e.PageSettings.Margins = new Margins(0, 0, 0, 0); 
 
Sample Link 

Regards, 
Amal Raj U. 



HU Hussain November 22, 2016 12:06 PM UTC

Hi Amal.

It worked for the grid to occupy the header place, but still not filling the hole page.
I also noticed (in your example too) that the grid size in the rest of pages (except the last page) is the same as the grid in the first page despite of the extra space in the rest of pages which has been created by removing header. 

Note : if you attached an example i prefer it to be written with vb.net not C#. I also attached a sample output.

Thanks in advance

Attachment: header_1ca46f6d.rar


AR Amal Raj U Syncfusion Team November 23, 2016 02:15 PM UTC

Hi Hussain, 

Thanks for the update. 

By default, number of records that’s going to print in single page is calculated internally before printing the grid data. Since there is no direct support for hiding the Headers in particular page, managing the margins of page will result in some empty spaces. This cannot be removed directly. 

However the space can be avoided by printing some more records of grid by specifying the records to be printed using PrintInfo.m_awPageFirstRow collection which maintains the number of records to be printed in each page. By modifying this collection with our records, we can remove the unwanted spaces. Please make use of the below code, 
 
Code Example 
bool firstPagePrinted = true; int pageIndex = 1; int NoOfRecordsToAdd = 2; 
void printDocument_PrintPage(object sender, PrintPageEventArgs e) 
{ 
    if (firstPagePrinted) 
    { 
        e.PageSettings.Margins = new Margins(0, 0, 0, 0); 
        if (pageIndex + 1 < this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count) 
        { 
            int nextFirstRowValue = (int)this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[pageIndex + 1]; 
            int lastRowValue = (int)this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count - 1]; 
            if (nextFirstRowValue + (pageIndex * NoOfRecordsToAdd) < lastRowValue) 
                this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[pageIndex + 1] = nextFirstRowValue + (pageIndex * NoOfRecordsToAdd); 
            else 
            { 
                this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[pageIndex + 1] = (int)this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow[this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count - 1]; 
                for (int i = pageIndex + 2; i < this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count; i++) 
                { 
                    this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.RemoveAt(i); 
                } 
            } 
        } 
        pageIndex++; 
    } 
} 
 
Sample Link 

Note 
NoOfRecordsToAdd defines the number of records to be added in the remaining empty spaces. The above customization for changing the PrintInfo.m_awPageFirstRow may differs with your Grid’s bounds based on remaining empty spaces. You can customize the PrintInfo.m_awPageFirstRow as per your remaining empty spaces. 
 
If the number of records to be printed in the page exceeds the maximum bounds area, then that page will not printed. 
 
Regards, 
Amal Raj U. 



HU Hussain November 29, 2016 12:06 PM UTC

Hi Amal.

Thanks. Almost every thing worked fine except this part,

for (int i = pageIndex + 2; i < this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.Count; i++) 
                { 
                    this.gridGroupingControl1.TableControl.PrintInfo.m_awPageFirstRow.RemoveAt(i); 
                } 

which some times generates index out of bound exception but i fixed it by replacing it with these lines,

While gridP.TableControl.PrintInfo.m_awPageFirstRow.Count > pageIndex + 2
                        gridP.TableControl.PrintInfo.m_awPageFirstRow.RemoveAt(gridP.TableControl.PrintInfo.m_awPageFirstRow.Count - 1)
                    End While


AR Amal Raj U Syncfusion Team November 30, 2016 04:24 AM UTC

Hi Hussain, 

Thanks for the update. 

We are glad to know that you have resolved the issue with the provided solution. Please let us know, if you have any concerns. 

Regards, 
Amal Raj U. 


Loader.
Up arrow icon