Rank: Newbie Groups: Member
Joined: 12/10/2012 Posts: 9
|
I have the below code for generating my pdf. However, the header only appears on the first page and says there is a total of one page, not 3.
ie Page 1 of 1.
If I put the page header code AFTER adding the pages then none of the pages have a header.
In addition, how do I have the download default to a ".pdf" instead of ".aspx" ?
Thank you for your help!
~~~~
//Set the response header HttpResponse response = HttpContext.Current.Response; response.Clear(); response.ClearHeaders(); response.ContentType = "application/pdf";
PdfDocument doc = new PdfDocument();
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0.5f, 0.5f, 7.5f, 10f); HtmlToPdf.Options.HeaderHtmlFormat = @" <div style=""font-size: .9em; font: 12px Arial;""> <div style=""float:right; position:relative;"">Page {page_number} of {total_pages}</div> <b>Work Order</b><br /> Work Order Number: 000.0<br /> Service Provider: [SERVICE PROVIDER] </div>"; HtmlToPdf.Options.HeaderHtmlPosition = 0.4F; HtmlToPdf.Options.GeneratePageImages = true; HtmlToPdf.Options.RepeatTableHeaderAndFooter = true;
//Convert to the output stream HtmlToPdf.ConvertUrl(ConvertRelativeUrlToAbsoluteUrl("~/wo/wo-template/Page1.aspx"), doc); HtmlToPdf.ConvertUrl(ConvertRelativeUrlToAbsoluteUrl("~/wo/wo-template/Page2.aspx"), doc); HtmlToPdf.ConvertUrl(ConvertRelativeUrlToAbsoluteUrl("~/wo/wo-template/Page3.aspx"), doc); doc.Save(Response.OutputStream); response.End();
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi, That's normal. HeaderHtmlFormat works WITHIN a single conversion. Since each of your conversion produces just one page, the total page number is 1 for each of these conversions. In your case, you can make additional ConvertHtml class to "stamp" the page header after you have completed all three ConvertUrl calls. The code will be something like this:
Code: C#
foreach (PdfPage page in doc.Pages)
{
//Set the output area to the HEADER area
HtmlToPdf.Options.OutputArea = ....
//Format your HTML to contain the right page number
string html = .....
//Note the second argument is a PdfPage object, not a PdfDocument object
HtmlToPdf.ConvertHtml(html, page);
}
Hope this helps. Thanks!
|