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.
Unfortunately, activation email could not send to your email. Please try again.

Header different for eachpage

Thread ID:

Created:

Updated:

Platform:

Replies:

121265 Nov 24,2015 12:07 PM Nov 25,2015 07:43 AM Silverlight 1
loading
Tags: PDF
Anthony PALLINI
Asked On November 24, 2015 12:07 PM

Hello,

I need to add a "parameter" in my header :
I have a title that include the report date (i have this parameter in my code) and for each page in the pdf, i have a different date.
I can't create a title outside the header since content can be on 2 page (when grid has too much line)

Thanks in advance,

Bye.

Abirami Selvan [Syncfusion]
Replied On November 25, 2015 07:43 AM

Hi Anthony,
Thank you for contacting Syncfusion support.
We can draw the grid table with particular paginate bounds and can add the different headers using sections for each page. We have created the code according to your requirement.
Please refer to the in the following code example:

C#:

// Create a new PdfDocument

PdfDocument document = new PdfDocument();


// Add a page

PdfPage page=document.Pages.Add();


//Create the pdfgrid

PdfGrid pdfGrid = new PdfGrid();


//Add grid columns

pdfGrid.Columns.Add(5);


//Add the grid row

for (int i = 0; i < 4; i++)

pdfGrid.Rows.Add();



//Assign the values to table

for (int i = 0; i < 30; i++)

{

pdfGrid.Rows[i].Cells[0].Value = i.ToString() + " Row ";


}


//Apply the pagination

PdfGridLayoutFormat gformat = new PdfGridLayoutFormat();

gformat.Layout = PdfLayoutType.Paginate;

gformat.Break = PdfLayoutBreakType.FitPage;

gformat.PaginateBounds = new RectangleF(10, 10, page.GetClientSize().Width, page.GetClientSize().Height);


//Draw the table

pdfGrid.Draw(page, new PointF(0, 10), gformat);


MemoryStream ms = new MemoryStream();


// Save and close the document.

document.Save(ms);

document.Close(true);


ms.Position = 0;


//Load the file stream that contains the grid.

PdfLoadedDocument ldoc = new PdfLoadedDocument(ms);


//Create the document.

PdfDocument finalDoc = new PdfDocument();


//set the margins

finalDoc.PageSettings.SetMargins(0f);


for (int i = 0; i < ldoc.Pages.Count; i++)

{

//Get the templates from loadeddocument.

PdfTemplate template = ldoc.Pages[i].CreateTemplate();


//Add the sections

PdfSection section1 = finalDoc.Sections.Add();

PdfPage page1 = section1.Pages.Add();


//Draw the templates

page1.Graphics.DrawPdfTemplate(template, new PointF(0,0),new SizeF(page1.GetClientSize().Width,page1.GetClientSize().Height));


//Including header to the section

section1.Template.Top = AddHeader(finalDoc, DateTime.Now.Date.ToShortDateString());

}

MemoryStream stream = new MemoryStream();


//Desired document is saved and opened

SaveFileDialog saveDialog = new SaveFileDialog()

{

DefaultExt = ".pdf",

Filter = "Adobe PDF Files(*.pdf)|*.pdf",

FilterIndex = 1

};

saveDialog.ShowDialog();


using (Stream stream1 = saveDialog.OpenFile())

{

finalDoc.Save(stream);

}


//close the document

finalDoc.Close(true);

ldoc.Close(true);

stream.Dispose();
MessageBox.Show("Document has been successfully generated", "Essential PDF", MessageBoxButton.OK);





private PdfPageTemplateElement AddHeader(PdfDocument doc, string title)

{


RectangleF rect = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50);


//Create page template

PdfPageTemplateElement header = new PdfPageTemplateElement(rect);

PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);


//Set formattings for the text

PdfStringFormat format = new PdfStringFormat();

format.Alignment = PdfTextAlignment.Center;

format.LineAlignment = PdfVerticalAlignment.Middle;


//Draw title

header.Graphics.DrawString(title, font, PdfBrushes.Black, new RectangleF(0, 0, header.Width, header.Height), format);

header.Graphics.DrawRectangle(PdfPens.Blue, rect);



return header;


}



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

Regards,
Abirami.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;