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\PDFH elper\"+sFileNa me + ".html"); //Replace ~\common\PDFHel per\ 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 [ ]
ReplaceCheckBox Controls(page.C ontrols);
StreamWriter sWriter = File.CreateText (sPage);
System.Web.UI.H tmlTextWriter htw = new System.Web.UI.H tmlTextWriter(s Writer);
page.RenderCont rol(htw);
htw.Close();
sWriter.Close() ;
System.Diagnost ics.Process pProcess = new System.Diagnost ics.Process();
pProcess.StartI nfo.FileName = Server.MapPath( @"~\common\PDFH elper\ghtmldoc. exe");
pProcess.StartI nfo.Arguments = "--webpage --quiet " + sFontSize + m_sWaterMark + " --bodyfont verdana " + sLandScape + " -t pdf14 -f " + sFileName + ".pdf " + sFileName + ".html";
pProcess.StartI nfo.WorkingDire ctory = Server.MapPath( @"~\common\PDFH elper");
pProcess.Start( );
2a.Here is ReplaceCheckbox control function to help you out
private void ReplaceCheckBox Controls(Contro lCollection controls)
{
for (int i=controls.Coun t -1; i>=0; i--)
{
if(controls[i].HasControls())
ReplaceCheckBox Controls(contro ls[i].Controls);
else if(controls[i] is CheckBox)
{
ReplaceCheckBox Controls(contro ls[i] as CheckBox);
}
else if(controls[i] is Label)
{
Label lbl = controls[i] as Label;
if(lbl.Text == string.Empty)
lbl.Text = " &nbs p;";
}
}
}
private void ReplaceCheckBox Controls(CheckB ox chkBox)
{
if(chkBox.Paren t != null)
{
Control parent = chkBox.Parent;
int idx = parent.Controls .IndexOf(chkBox );
parent.Controls .RemoveAt(idx);
LiteralControl literal = new LiteralControl( );
parent.Controls .AddAt(idx,lite ral);
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**********@y ahoo.co.ukwrote in message news:11******** **************@ h48g2000cwc.goo glegroups.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.