1

I'm trying to create a control that converts the page it's on into a PDF.

protected void ConvertPageToPDF_click(object sender, EventArgs e)
{
    string pageHtml;
    byte[] pdfBytes;

    string url = HttpContext.Current.Request.Url.AbsoluteUri;

    // get the HTML for the entire page into pageHtml
    HtmlTextWriter hw = new HtmlTextWriter(new StringWriter());
    this.Page.RenderControl(hw);
    pageHtml = hw.InnerWriter.ToString();

    // send pageHtml to a library for conversion
    // send the PDF to the user
}

This partially works. On my pages I have several repeaters; their content does not show up in pageHtml. Any thoughts on why that is? How should I fix this?

user1269310
  • 342
  • 3
  • 13
  • Maybe this link helps you: http://stackoverflow.com/a/1008567/1406728 http://stackoverflow.com/a/5320157/1406728 – Lars May 22 '12 at 18:39

1 Answers1

2

It turns out that I had to render the control after the data had been bound to it. My click method just adds an event handler:

protected void ConvertRepeaterToPDF_click(object sender, EventArgs e)
{
    // handle the PreRender complete method
    Page.PreRenderComplete += new EventHandler(Page_OnPreRenderComplete);
}

Then in Page_OnPreRenderComplete I can use RenderControl as above.

user1269310
  • 342
  • 3
  • 13