Rank: Newbie Groups: Member
Joined: 3/8/2016 Posts: 1
|
I recently upgraded from 16.0.17.0 to 17.2.43.0. After this upgrade the code to add a footer to each page is no longer being invoked. I modified the DemoController in the PdfMvc_CS sample project that is installed with Essential Objects to demonstrate the problem. The AfterRenderPage code is never called.
Code: C#
public ActionResult Input(AddressModel m)
{
if (m.ExportToPDF)
{
EO.Pdf.HtmlToPdf.Options.AfterRenderPage += new EO.Pdf.PdfPageEventHandler(On_AfterRenderPdfPage);
MVCToPDF.ResultFileName = "AddressLabel";
if (m.SaveAsFile)
MVCToPDF.SendToClient = false;
MVCToPDF.RenderAsPDF();
}
return View("AddressLabel", m);
}
public void On_AfterRenderPdfPage(object sender, EO.Pdf.PdfPageEventArgs e) {
AcmRender render = new AcmRender(e.Page, 0, new AcmPageLayout(new AcmPadding(0.5f, e.Page.Size.Height - 0.45f, 0.5f, 0.0f)));
AcmBlock footerLeft = new AcmBlock(new AcmText(DateTime.UtcNow.ToShortTimeString()));
footerLeft.Style.Top = 0.0f;
footerLeft.Style.HorizontalAlign = AcmHorizontalAlign.Left;
footerLeft.Style.FontName = "Arial";
footerLeft.Style.FontSize = 8.0f;
string footerRightContent = e.Page.Index == 0
? "Copyright \u00A9 1999"
: string.Format("Page {0} of {1}", e.Page.Index + 1, e.Page.Document.Pages.Count);
AcmBlock footerRight = new AcmBlock(new AcmText(footerRightContent));
footerRight.Style.Top = 0.0f;
footerRight.Style.HorizontalAlign = AcmHorizontalAlign.Right;
footerRight.Style.FontName = "Arial";
footerRight.Style.FontSize = 8.0f;
render.Render(footerLeft, footerRight);
}
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,258
|
Hi, You won't be able to use AfterRenderPage with MVCToPDF. You will need to use the afterConvertHandlerargument for RenderAsPDF method instead: https://www.essentialobjects.com/doc/eo.pdf.mvc.mvctopdf.renderaspdf_overload_2.aspxInside this handler you will have access to the result PdfDocument. You can then loop through each page and add header/footer on each page. Thanks!
|