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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Adding Javascript source link in footer of pdf.

Thread ID:





88112 Jul 15,2009 01:23 PM UTC Jul 22,2009 12:41 PM UTC ASP.NET Web Forms (Classic) 5
Tags: PDF
Raveesh Kumar
Asked On July 15, 2009 01:23 PM UTC


I am using asp.net 3.5 and C#. I am using Datatable to Pdf convertion functionality. I have a Url which I executes using Javascript "src" url and need to put this in footer of each page. This url randomly displays images on footer using javascript.

Can you please let me know how can we embedd javascript on footers of each page.

I am using Back Office | Essential PDF for ASP.NET

Early reply is appriciated as we need to finalize the product in 1-2 days.

Many Thanks

Sri Subhashini M [Syncfusion]
Replied On July 16, 2009 01:24 PM UTC

Hi Raveesh,

Here is the answers for your questions,

Adding Footer to the PDF page

We can draw header for each PDF page by using the Top property of the PdfTemplate class. Kindly use the below code to draw the page template at top of the PDF page.

//Create a PDF document
PdfDocument doc = new PdfDocument();
// Add a new section
PdfSection sec = doc.Sections.Add();
//Create page template
PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
//Add header template at the top.
sec.Template.Top = header;

Showing Table column header
We can show the table column by enabling the ShowHeader property of the PdfLightTable. Kindly look into the below code snippet to enable the ShowHeader property,

//Create a new table.
PdfLightTable table = new PdfLightTable();
table.Style.ShowHeader = true;

Javascript in Footer

I was able to understand your requirement which you mentioned here. We can execute the javascript using HtmlConverter by specifying the URL as like,

[HTML Code]
script language='javascript' type='text/javascript' src='http://www.beckett.com/banmanpro/Sequence2.aspx?ZoneID=226&CountImpressions=True&Total=4&SiteID=1&Horizontal=True&MaxColumns=4'

Please do find the below sample which demonstrates the above mentioned features and let me know if this helps,


Raveesh Kumar
Replied On July 17, 2009 06:50 AM UTC

Thanks for the example.
The JavaScript link provided in page “HtmlTable.html”, if executed repeatedly, displays different set of images each time.
For example if we open the html page “HtmlTable.htm” provided in link “http://files.syncfusion.com/samples/PDF.Web/57911/main.htm”, in browser and hit refresh button, it will display new set of htperlinked images each time. What I want to accomplish is, that link provided in “HtmlTable.html” should be processed on each page so that it will display different images on each page footer.

As per example you have provided you have executed this.footer() function twice and hence both pages are displaying different set of images. But in my application numbers of pages are determined at run time only. Also all these images are hyperlinks which let users to click on this footer images to go to specified Url. This url is the main requirement for footer images.

So can you please help me, how can we put this link in each of the page footers, so that all pages will show different set of clickable image links.

Sri Subhashini M [Syncfusion]
Replied On July 17, 2009 12:44 PM UTC

Hi Raveesh,

Drawing Different footers on PDF page

We can draw the generated images of the “HtmlTable.html” in every page dynamically by using the Pages_PageAdded event handler. The event Pages_PageAdded raised on adding a new page to the PDF document. Kindly refer the below code snippet which demonstrates drawing the different footers on each page,

void Pages_PageAdded(object sender, PageAddedEventArgs args)
PdfTemplate footer;
using (HtmlConverter html = new HtmlConverter())
// set Javascript
html.EnableJavaScript = true;
using (HtmlToPdfResult result = html.Convert(Server.MapPath('~/Data/HtmlTable.htm'), ImageType.Metafile, (int)doc.Pages[0].GetClientSize().Width, (int)220, AspectRatio.KeepWidth))
if (result.RenderedImage == null)
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
//Create a page template
footer = new PdfTemplate(new SizeF(doc.Pages[0].GetClientSize().Width, 100));
footer.Graphics.DrawImage(PdfImage.FromImage(result.RenderedImage), new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 200));
args.Page.Graphics.DrawPdfTemplate(footer, new PointF(0, 670));

Images with Hyperlinks

We can achieve the behavior by using PdfUriAnnotation. We have to draw the URL in the specified page location. Kindly refer the below code snippet to draw the URL in the specified page location,

PdfUriAnnotation url2 = new PdfUriAnnotation(new RectangleF(240, 670, 170, 45));
url2.Uri = 'http://www.Yahoo.com';
url2.Border = new PdfAnnotationBorder(0, 0, 0);
url2.Color = new PdfColor(Color.White);

Please do find the sample from the below specified location and let me know if you need any information,


Raveesh Kumar
Replied On July 21, 2009 02:55 PM UTC

Thanks for your help.
One thing which i have noticed that, if I use PageAddedEventArgs to create new footers on each page, then pdf size incresed approximately 30 times the pdf, which was created without page PageAddedEventArgs.

Before using PageAddedEventArgs handler i was using
Template.OddBottom and Template.OddBottom.

I have also included
"doc.Compression = Syncfusion.Pdf.PdfCompressionLevel.Best;"
Still its size is 60 mb. which otherwise was of 2.6 mb.

Can you please let me know what could be the possible cause.

Many Thanks

Sri Subhashini M [Syncfusion]
Replied On July 22, 2009 12:41 PM UTC

Hi Raveesh,

File size increased on drawing custom footer

Basically, the PdfPageTemplateElement is an common area which is shared by all the pages within the document. If we assign the footer to a PDF document using PdfPageTemplateElement, the footer information will be shared by all the pages of the PDF document. PDF document`s pages doesn`t contain information about its footer elements.

But according to your requirement, We are drawing our own footer kind of thing for each page externally, which is not an actual footer.

Since we have several images placed on the footers on each page, we could see this much difference in file size. This is not an issue. We can resolve this issue by making use of the document footers, but your specific requirement of having different footer on each page could not be achieved if we switch to this approach.

Please let me know if you need any information.



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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon