473,473 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

convert html to pdf

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.

Sep 22 '06 #1
2 4745
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.
Sep 22 '06 #2
Hello suji,

Why to use 3rd part tools if you can convert it manually using XSL-FO
see manual there http://www.antennahouse.com/XSLsample/XSLsample.htm

sHai,
s>
sAre there any 3rd party controls who provide free libraries to
sconvert
smy html form to pdf in c#?
sI need to have a button on my form, that should convert my page to
spdf
sformat. Can any one help me to write code for that in c# with
slibraries?
sregards,
sSuji.
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
I want to use XML to store a document's configurations. And I can convert to different file format by using XSL. For example, convert to HTML, PDF, or RTF. But the contents are all stored in single...
4
by: Dominic | last post by:
Hi guys, In .NET, how can I convert a HTML file to TIFF efficiently? One possible way is that I can first use word automatation to load the HTML up and then print it to TIFF. Is that right?...
3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
3
by: iwdu15 | last post by:
hi, how can i convert rtf encoding to HTML? i looked at previous posts and i cant seem to find the HTTPUtility in vbexpress 2005. Is it not there, and is there another way? thanks -- -iwdu15
5
by: melickas | last post by:
We designed a custom application using Office Developer Tools '97 which included a Run-time version of Access--- so it would not matter if our customer even had any version of Access on their...
6
by: PenguinPig | last post by:
Dear All Experts I would like to know how to convert a HTML into Image using C#. Or allow me contains HTML code (parsed) in Image? I also tried this way but it just display the character "<" &...
2
by: csgraham74 | last post by:
Hi, I have a requirement in work that i give a person the ability to create a html document using a richt text editor. What i then want to do is save the HTML doct to my server & insert...
4
by: csgraham74 | last post by:
Hi, Ive posted on this previously but had no response. Basically i need to build some html using a rich text editor. Then i want to actually create an html document from this and save it to my...
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
5
by: Just Another Victim of the Ambient Morality | last post by:
I've done a google search on this but, amazingly, I'm the first guy to ever need this! Everyone else seems to need the reverse of this. Actually, I did find some people who complained about this...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.