Welcome Guest Search | Active Topics | Sign In | Register

How can I get a pdf file "total pages count" before render page? Options
ITRI
Posted: Thursday, October 3, 2013 6:17:00 AM
Rank: Newbie
Groups: Member

Joined: 5/29/2013
Posts: 1
Hi,

here is my coding problem(using c#)

......

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

HtmlToPdf.ConvertHtml(htmlCode,pdfPath);

.......

private void On_AfterRenderPage(object sender, EO.Pdf.PdfPageEventArgs e)
{
int total page count=???;
AcmBlock footer = new AcmBlock(new AcmText(string.Format("{0}/{1}", e.Page.Index + 1,total page count)));
}

before a pdf document is created, EO renders page first, and I could not get the total page count
number. I need a page total count number to mark as

1/3
2/3
3/3 total page count is 3

and how can I get the number "3" when the real pdf file is not created yet?

thanks!!
eo_support
Posted: Thursday, October 3, 2013 10:13:54 AM
Rank: Administration
Groups: Administration

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

You can not. You do not have to use AfterRenderPage event. You can just add your footer after the ConvertHtml call. Your code can be something like this:

Code: C#
//Convert the HTML. Note you are converting to a PdfDocument
//object, not a physical file here (the second argument of
//ConvertHtml is a PdfDocument object)
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertHtml(htmlCode, doc);

//Use a loop to add footer
for (int i = 0; i < doc.Pages.Count; i++)
{
    //Now add footer to doc.Pages[i]
    .....
}

//Save the PDF file
doc.Save(pdfPath);


Hope this helps.

Thanks!


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.