Reputation: 1885
I'm having a complex issue here.
Context: I'm editing a forms-engine project that dynamically creates it's control based on an XML definition on each request, to add a PDF generation feature using Aspose.PDF. In brief, the forms-engine as a set of control that act as a basic functionality to fill out of form(textbox, phone number, date control etc.) each control and it's properties are defined in the xml files and correspond to an xml schema. Now, when the form is completed there's a formRepeater control that retrieves the previously filled page and format the data for printing in the web browser. I must replace this to generate a pdf file instead.
What I have done: I added a new abstract method called GeneratePdf that all FormControls must implement and I call this method for each control and sub-controls in my control container PreRender event. The method will be different depending on each control but here's the basic one for now
public override void GeneratePdf(Aspose.Pdf.Generator.Pdf file)
{
//Add the control HTML in a new section of the PDF File
var section = file.Sections.Add();
var sb = new StringBuilder();
var writer = new HtmlTextWriter(new StringWriter(sb));
this.RenderControl(writer);
var html = new Aspose.Pdf.Generator.Text(section, sb.ToString());
html.IsHtmlTagSupported = true;
section.Paragraphs.Add(html);
}
My problem: I'm successfully retrieving the HTML of my controls using the Stringbuilder, but if a control as standard ASP.NET controls inside them, the HTML of the child controls is not rendered. Why?
Thanks,
Upvotes: 1
Views: 808
Reputation: 3043
The RenderControl will render child-controls HTML into the sb stringwriter.
However, http://www.aspose.com/docs/display/pdfnet/Text+Constructor+Overload_3 Aspose Text do not automatically create the segments for each sub-controls. It expect the the string you passed to it to be for single (and current) segment.
To add the sub-controls of a control, you will need to recursively call/generate each sub-control. So you will need to restructure your code above.
Upvotes: 2