473,785 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ 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 4772
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.
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
1878
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 XML file. Are they any documentation management tools/web site that help people do that? please help. thanks!!
4
7049
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? However, even if it is technically feasible, it can take long time to do the conversion, especially the HTML is complicated. Is there any other more efficient way? Thanks!
3
7773
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 DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but double bytes become 2 seperate single bytes. Surely there is an easy way to convert these mixed...
3
3391
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
2577
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 computer. The application ran without problems on our customer's computer for 2-3 years. Then our customer bought a new computer and we had to reinstall the application. Everything was ok for approximately 6 months until our customer was "cleaning up"...
6
29450
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 "<" & ">" directly.... I have done googling, but all return shareware. I would like to know how to programming...but not using shareware... Thanks all.
2
4595
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 reference in a database so that i can retrieve the html document. Basically i dont have a clue how to convert a string in HTML format (taken from the RTE) to an actual document and then save it to a folder. Can anyone point me in the correct direction.
4
4477
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 server. Does anyone have any examples on how to do this ?? I dont really understand how to get from HTML string to HTML document. I can probably work out how to save this. do i create an html object ??
4
39345
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 will convert each of the records of these service dates to the first date of that month, with results showing: 7/1/2006, 7/1/2006, 7/1/2006. How would you place an expression on a query that will convert any given date to the first day of the month...
5
3646
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 and rolled their own solution but I refuse to believe that Python doesn't have a built-in solution to what must be a very common problem. So, how do I convert HTML to plaintext? Something like this: <div>This&nbsp;is&nbsp;a&nbsp;string.</div>
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.