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[i].HasControls())
ReplaceCheckBoxControls(controls[i].Controls);
else if(controls[i] is CheckBox)
{
ReplaceCheckBoxControls(controls[i] as CheckBox);
}
else if(controls[i] is Label)
{
Label lbl = controls[i] 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.
"suji" <su**********@yahoo.co.ukwrote in message news:11**********************@h48g2000cwc.googlegr oups.com...
Hai,
Are there any 3rd party controls who provide free libraries to convert
my html form to pdf in c#?
I need to have a button on my form, that should convert my page to pdf
format. Can any one help me to write code for that in c# with
libraries?
regards,
Suji.