Welcome Guest Search | Active Topics | Sign In | Register

Different first page header and footer Options
excelsys
Posted: Tuesday, January 3, 2012 9:44:26 AM
Rank: Member
Groups: Member

Joined: 1/3/2012
Posts: 10
How to set up first page's header and footer different from the rest of the pages?
eo_support
Posted: Tuesday, January 3, 2012 9:56:23 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You can set all pages to use the same header/footer first, then overwrite the first page's header/footer with code.

In order to overwrite the first page's header/footer, you would handle EO.Pdf.HtmlToPdf.Options.AfterRenderPage. See here for sample code:

http://www.essentialobjects.com/doc/4/htmltopdf/header.aspx#event

You will need to check the page number in your event handler:

Code: C#
//Only overwrite the page header/footer for the first page
if (e.Page.Index == 0)
{
    //Generate header/footer for the first page
    ....
}


Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
excelsys
Posted: Tuesday, January 3, 2012 10:14:19 AM
Rank: Member
Groups: Member

Joined: 1/3/2012
Posts: 10
Thanks for a quick reply!
Where do I put the statement

EO.Pdf.HtmlToPdf.Options.AfterRenderPage =
new EO.Pdf.PdfPageEventHandler(On_AfterRenderPage); ?

Thanks!
eo_support
Posted: Tuesday, January 3, 2012 10:19:20 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
I assume that you are using the HTML to PDF feature to convert your main content. In that case you put it before calling ConvertUrl/ConvertHtml.

Thanks
excelsys
Posted: Tuesday, January 3, 2012 10:50:30 AM
Rank: Member
Groups: Member

Joined: 1/3/2012
Posts: 10
Yes you are right, I am using html to pdf.

Thanks again for the pointer. I can now see that the On_AfterRenderPage is called.

In the On_AfterRenderPage routine, I overwrite the header by specifying

if (e.Page.Index == 0)
{
EO.Pdf.HtmlToPdf.Options.HeaderHtmlFormat = "";
}

but it doesn't seem to work; I still see the header in the first page.

Any clue?

Thanks!
eo_support
Posted: Tuesday, January 3, 2012 11:01:15 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
No. That's not how it works. You don't overwrite the page header/footer just by setting HeaderHtmlFormat. You overwrite the page header/footer by actually generating output ---- either by calling HtmlToPdf or use PDF Creator interface, and make sure the new output you generated is at the right location so it overlaps on top of default page header/footer (which were created based on HeaderHtmlFormat). Please see the sample code in the documentation again to see how it works. The key point is this is not a setting thing, it's code. Basically you write code to generate new output to cover up the old output.

Let us know if you still have any questions.

Thanks
lled
Posted: Monday, April 2, 2012 6:52:13 PM
Rank: Newbie
Groups: Member

Joined: 4/2/2012
Posts: 1
To use a completely different header on the first page rather than just adding to it, you have to 'hide' the header set through HtmlToPdf.Options.HeaderHtmlFormat. I do this by creating a div with a white background and rendering it over the default header, and then you once again have an empty header. The same can be done for the footer.

Code: C#
// only hide the header on the first page
if (args.Page.Index == 0)
{
    // create a div element that will cover up the default header
    string headerWhiteout = "<div style='background-color:#fff; width:850px; height:55px;'></div>";

    // save the output area
    var outputArea = HtmlToPdf.Options.OutputArea;
    
    // set the new output area to be over the header
    HtmlToPdf.Options.OutputArea = new RectangleF(0, 0, 8.5f, 1);
    
    // write the white div block over the header
    HtmlToPdf.ConvertHtml(headerWhiteout, args.Page.Document.Pages[0]);

    // set the output area back - no need to do this if you're not going to do any more processing
    HtmlToPdf.Options.OutputArea = outputArea;

    // ... any other after render page processing
}


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.