Rank: Newbie Groups: Member
Joined: 6/7/2012 Posts: 6
|
How to display total page number in page content not in header and footer.
Thanks
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
You can use PdfDocument.Pages.Count to get the total page number, then either use ConvertHtml or PDF Creator (ACM) interface to output the page number anywhere you want.
Thanks!
|
Rank: Newbie Groups: Member
Joined: 6/7/2012 Posts: 6
|
Hi, I used the code as shown below. I got the total page count always be empty.
Print button click
protected void BtnPrintPriview_Click(object sender, EventArgs e) { Button BtnPrint = (Button)((Control)(sender)); Session["url"] = "OrderPrint.aspx?OrderRef=" + TxtOrderRef.Text + "&TotalPages=" + TxtPTotalPages.Text + "&SupplierName=" + BtnPrint.CommandName + "&ItemIndex=" + BtnPrint.CommandArgument; ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('../PrintAsPdfForOrder.aspx','PrintMe','height=600px,width=600px,scrollbars=1');</script>"); }
PrintAsPdfForOrder page
public partial class PrintAsPdfForOrder : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {
Runtime.AddLicense(licence key); PdfDocument doc = new PdfDocument(); HtmlToPdf.Options.FooterHtmlFormat = "Page {page_number}"; HtmlToPdf.Options.AfterRenderPage = new PdfPageEventHandler(On_AfterRenderPage); string url = Request.Url.ToString(); string[] str = url.Split('?'); url = str[0].Replace("PrintAsPdfForOrder.aspx", Convert.ToString(Session["Url"])); if (url.Contains("?")) { url = url + "&Pages=" + doc.Pages.Count.ToString();//Attach the page count with url } else { url = url + "?Pages=" + doc.Pages.Count.ToString(); } HtmlToPdf.ConvertUrl(url, doc);
//url is the url to a page that I want to print .Retrieve page count from url and bind in print page HttpResponse response = HttpContext.Current.Response; response.Clear(); response.ClearHeaders(); response.ContentType = "application/pdf"; doc.Save(response.OutputStream); }
}
private void On_AfterRenderPage( object sender, EO.Pdf.PdfPageEventArgs e) { EO.Pdf.HtmlToPdf.Options.OutputArea = new RectangleF(0.1f, 0.1f, 8.3f, 12f); EO.Pdf.HtmlToPdf.ConvertHtml(@"<div style='width:300px;height:74px;margin:auto;'><img src='http://www.medarabco.com/images/med-logo.jpg' width='300' height='74' ></div></div>", e.Page);
} }
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
We won't review or debug your code. You have to explain why you think your code should work first.
Thanks!
|