if your form is not filled with complicated controls you can use ghtmldoc.exe.
Step 1:
Google ghtmldoc.exe and get licensed copy or use the olde version. Once you got the file
Step2 :
Create the function in your form say like GeneratePDF()
string sFileName = "test.html";
string sPage = Server.MapPath(@"~\common\PDFHelper\"+sFileName + ".html"); //Replace ~\common\PDFHelper\ with your directory of choice
//Checkbox's are converted by this tool to pfd , so we are going to replace all the checkboxes with
//literal control with text [ ]
ReplaceCheckBoxControls(page.Controls);
StreamWriter sWriter = File.CreateText(sPage);
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sWriter);
page.RenderControl(htw);
htw.Close();
sWriter.Close();
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = Server.MapPath(@"~\common\PDFHelper\ghtmldoc.exe");
pProcess.StartInfo.Arguments = "--webpage --quiet " + sFontSize + m_sWaterMark + " --bodyfont verdana " + sLandScape + " -t pdf14 -f " + sFileName + ".pdf " + sFileName + ".html";
pProcess.StartInfo.WorkingDirectory = Server.MapPath(@"~\common\PDFHelper");
pProcess.Start();
2a.Here is ReplaceCheckbox control function to help you out
private void ReplaceCheckBoxControls(ControlCollection controls)
{
for (int i=controls.Count -1; i>=0; i--)
{
if(controls.HasControls())
ReplaceCheckBoxControls(controls.Controls);
else if(controls is CheckBox)
{
ReplaceCheckBoxControls(controls as CheckBox);
}
else if(controls is Label)
{
Label lbl = controls as Label;
if(lbl.Text == string.Empty)
lbl.Text = " ";
}
}
}
private void ReplaceCheckBoxControls(CheckBox chkBox)
{
if(chkBox.Parent != null)
{
Control parent = chkBox.Parent;
int idx = parent.Controls.IndexOf(chkBox);
parent.Controls.RemoveAt(idx);
LiteralControl literal = new LiteralControl();
parent.Controls.AddAt(idx,literal);
literal.Text = "[ ] "+ chkBox.Text;
}
}
3.After the above step forward your request to the new aspx page name it something like DispalyPDf or ViewPDF , on the page load sleep for 1000 miliseconds and
check for the pdf file you created using ghtmdoc.exe, if it's avialbale render that file to the browser.
I hope this helps.