convert html to pdf in .net

 I would like to convert HTML document into .pdf file. I have all HTML data into DIV & would like to convert all DIV data into .pdf. I am using below mentioned code but it does not work. can you please let me know how to do it?

I am using ASP.NET 2.0 with C#. 

Response.Clear();

Response.Buffer =
true;

HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "File.pdf"));

Response.ContentType = "application/pdf";

//Response.ContentType = "application/ms-excel";

//Response.Charset = "";

this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

//this.ClearControls(dg);

divMoneyMapPDFExport.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.Flush();

Response.End();


Thanks & Regards,
Padam Kumar Tripathi
padam_india@yahoo.com,
padam_india@hotmail.com
http://padam.8k.com
0
padam_padam
6/6/2008 9:23:48 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
962 Views

Similar Articles

[PageSpeed] 26

You can't do it like that. Consider using:

http://itextsharp.sourceforge.net/

Here's how:

http://itextsharp.sourceforge.net/tutorial/ch01.html

0
HeartattacK
6/6/2008 9:35:08 PM

That is the correct way to send back data that is already in pdf format. The data you are sending back though is in html format which is why it is not working for you. There are a number of ways to convert html to pdf. I have included a link to a commercial library that I have used to do this.

http://www.winnovative-software.com/html-to-pdf-converter.aspx 
 

0
cunningham
6/7/2008 4:03:45 AM

 http://www.html-to-pdf.net/

 

this is cheaper then all third party products  



View Blog

linkedin Asp.net Group

Don't forget to click “Mark as Answer” on the post that helped you
0
sameer_khanjit
6/7/2008 5:13:15 AM

Hi,

There are lots of Three-Party Control to achieve it. One of them is ABCPDF.NET which is convenient to use.

You can try it to operate and read/create your PDF file. There is a link to download: http://www.websupergoo.com/download.htm

There is a great demo available in the above link and you can learn how to use it.

Support document: http://www.websupergoo.com/support.htm 

Feature chart: http://www.websupergoo.com/abcpdf-8.htm

To get the datasource to creat pdf, you need to get the HTML of the currect page via Render event.

  protected   override   void   Render(HtmlTextWriter   writer)     
  {   
                System.IO.StringWriter   sw;   
                HtmlTextWriter   htmltw;   
                sw   =   new   System.IO.StringWriter();   
                htmltw   =   new   HtmlTextWriter(sw);   
                base.Render(htmltw);   
                htmltw.Close();   
                sw.Close();   
                String   tempsource   =   sw.ToString();   
                //tempsource is the datasource of pdf, please save it to another place.   
                writer.Write(temp);   
  }
To get the HTML of external page which is not currect, you can try the below codes:
    private void saveURL(string url)
    {
        if (!string.IsNullOrEmpty(url))
        {
            string content = "";

            System.Net.WebRequest webRequest = WebRequest.Create(url);
            System.Net.WebResponse webResponse = webRequest.GetResponse();
            System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
            content = sr.ReadToEnd();
            //content is the datasource of pdf, please save it to another place.   
        }
    }

You can call the method like:  saveURL("http://forums.asp.net/t/1201527.aspx"); Please pay attention on the format of URL, "http://" is necessary. Without it, you will encounter the error "The format of the URI could not be determined. "

You can get more information at: http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm

Hope this can help.

The Third-Party control isn't made by microsoft. If any accident occurs during the process, please connect with the organization of the product.

 



Vince Xu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Vince
6/10/2008 7:33:15 AM
Reply:

Similar Artilces:

how to convert dynamicaly loading images to pdf using HTML to PDF Converter for .NET
how to convert dynamicaly loading images to pdf using HTML to PDF Converter for .NET Now am converting using how to convert dynamicaly loading images to pdf using HTML to PDF Converter for .NET  tool. But the dynamicaly loading images are not showing in the pdf .     Are you using 3rd party tool or you are using iTextSharp free utility? If it is 3rd party tool, it's always suggested to ask the company which built the tool. Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti Hi vishnusekhar, As to convert images/douments ...

converting to vb.net from c#.net authorize.net
authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll"); } private String readHtmlPage(string url) { ...

Regarding Converting DataSet to PDF format in C#.Net/VB.Net
Hi, I can anyone help me regarding conversion of an dataset to PDF format. Thank YouMark as Answer if it helped youGayathri gayathri.pmsc: Hi, I can anyone help me regarding conversion of an dataset to PDF format. Thank You Either do it using Crystal Reports or create an html ny looping though dataset and then to pdf using itextsharp http://hamang.net/2008/08/14/html-to-pdf-in-net/MAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets...

Converting classic to .NET 2 code, and .NET gets an error back from ADS?
 For future-proofing, our Internal Phone Directory is being moved onto our AD servers, and obviously we're using LDAP for queries.To get the phoneboook queries working, I adapted the current classic ASP code to use LDAP, and that works fine. However, we're wanting to move these pages to .NET, and that's where the problem comes in. Using the same basic logic from the Classic code (90% of its unchanged) to produce an LDAP query, I get the error  155 Unknown error (0x80005000)This is using the same website, and so the same credentials  - unless aspx pages run und...

used a c#.net to vb.net converter and am now getting a syntax error.
ok I used a cool utility at http://www.kamalpatel.net/ConvertCSharp2VB.aspx to convert some c#.net to vb.net and it spit out a bunch of code which almost works but I am getting a syntax error on this line Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) I tried it that way and also like Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) but either way gave the same error Compiler Error Message: BC30035: Syntax error. Source Error: Line 26: Line ...

Net:Net:Net::LDAP::FAQ
------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

Converting from vb.net to c#.net
Hello I have recently purchased VBGolds RawDataPrinter which should allow users to print directly to label printers on our network directly from a c# web form.  Unfortunately they only supply vb.net examples and I have need of c#.  The component has been installed on our web server.  This is some code that they have supplied as examples in vb.net   "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >"Head1" runat="server&qu...

CONVERT VISUALBASIC.NET TO C#.NET!
Hi theretrying to complete a login page.  The example I have is written in visual basic, can you please convert the following statement into C# for a submit button (transferring data to a database!!):Sub btnSubmit_Click(sender As Object, e As EventArgs)   If Page.IsValid then      InsertGuestbookEntry(name.Text, email.Text, message.Text)      Response.Redirect("ViewGuestbook.aspx")   End IfEnd SubAlso, the following for retrieving data from a database into a drop down menu:Sub Page_Load (sender as ...

Starting an Ajax.net Application in .net
i am new to ajax.net could any one give me simple ajax,net example so that i start building on my ajax skills please.........  I started with the todolist video on the main asp.net/ajax page, and its all you need to know to get started. http://download.microsoft.com/download/0/f/6/0f651a0f-6f2b-4497-b061-e1b2825e22e0/MSAJAX-ToDoList.wmv Don't forget to click "Mark as Answer" on the post that helped you.This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped. http://asp.net/ajax/    ...

how to get start with .NET
the net help people installed  to my desktop 1-microsoft visual studio .NET enterprise developer 2003 2-microsoft .NET framework 1.1 what else do i need ...???  and how can i try with some simple code in VS.Net and run it to see wat happen...????? please help If you want to develope web applications, then you'll also need IIS on your PC.  That'll require XP-Professional or Windows 2000/2003, but XP-Home edition won't allow IIS installation. As for how to get started, you can search the web for some tutorials or buy a good book on VS.  The topic is way too vast to...

Getting Start With .net
hi i'm intersted to learn asp.net (vb or delphi) . i programming with delphi6 but i'd like to tp know something about programming in internet specially with .net . i hear about microsoft.net with delphi 7 that i can programming with delphi in .net .... is it right ? what 's our opinian about it ? and better to learn Vb.Net or continu with delphi(or delphi.net) thanks. Ali Darabian I think there is some support for Delphi in .Net. However, you will find much more support from the user community if you choose a more popular language such as VB.Net or C#. Since your al...

convert html to .net
 hi,alli put the html code into textbox.in run mode i want design in button click eventplz help me saipooja  do u want to render html written in textbox ?Mohamed Abb@s------------------------Please remember to click “Mark as Answer” on the post(s) which helps you ! Can you explain again what u want?Ameemark as answer if my reply helps you. If you are talking about click event programatically then try this:   Button1.Click += new ClickEventHandler(...)    "Mark As Answer" If my reply helped you -- Cannot understand, the exact requirement. What a...

Convert VB.Net application to C#.net
Haican any one help me to convert VB.Net application in this link to C#.net http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6718&lngWId=10RegardsAnu Palavila  Regards Anu Palavila Use this Free Conversion tool - http://www.developerfusion.com/tools/convert/vb-to-csharp/  ASP.NET Grid With Excel Capabilities | 27 GridView Tips & Tricks | Hosting your site? | SQL Server Tips Other Code Convertors (convert VB to C# and C# to VB) http://converter.telerik.com/ http://www.developerfusion.com/tools/convert/csharp-to-vb/ http://www.dotnetspider.com...

.net 3.5 convert to .net 2?
 how can i convert in Web Developer 2008 .net framework 3.5   to .net 2 ? KAHREDEN HAREKET ENGELLENNEMEZ  Hi,If you have not used any .NET 3.5 controls, you simply need to remove all references to .NET 3.5 within the web.config. I hope this helps, if it answers your question, don't forget to mark it as such for those who come afterwards.Regards,Gareth ChidgeyManaging DirectorPushInternet Ltd  ok.how  can i create new web site in web developer 2008 at .net framework 2  .    KAHREDEN HAREKET ENGELLENNEMEZ  try this http://we...

Web resources about - convert html to pdf in .net - asp.net.getting-started

List of converts to Buddhism - Wikipedia, the free encyclopedia
Ajahn Brahm (born 1951), Religious teacher and student of the late Thai monk Ajahn Chah . Currently he is the abbot of the Bodhinyana Monastery, ...

Facebook Timeline For Pages: 8 Million Converts, 29 Million To Go
... reach to 98 percent of users who liked its page, as well as to double its engagement rate, during a 28-day period. Dr. Pepper hasn’t yet converted ...

Facebook stock roundup: Execs offload more stock, directors convert shares
... Bowles, the former co-chair of the now-defunct National Commission on Fiscal Responsibility and Reform, and Reed Hastings, Netflix CEO, converted ...

How to Convert Leads Into Buying Customers - The 9 Step Sales Process EVERYONE Should Use
... School of Business in Toronto on the topics of Sales and Entrepreneurship. I shared with them the sales process that I find How to Convert Leads ...

Bitcoin : Should I convert my savings to Bitcoin?
Answer (1 of 7): You should think of this question as "Should I invest all my savings in Bitcoin?", and not "Should I have my savings denominated ...

Coordinates - Calculate and Convert a Position on the App Store on iTunes
Get Coordinates - Calculate and Convert a Position on the App Store. See screenshots and ratings, and read customer reviews.

Catholics should not convert Jews, says Vatican, in push against anti-Semitism
... 50 years since the Vatican's repudiation of the concept of Jewish guilt for Jesus' death.  Vatican City: Catholics should not try to convert ...

Opinion: These 5 things made me a happy iPad Pro convert
... like I needed a bigger device. But after three weeks with my iPad Pro, several things have changed my mind, and I’m officially a happy convert ...

$100 device converts all your film to digital photos
... still on film negatives. Today, we've got the perfect Amazon Cyber Week deal for you: A Wolverine F2D Mighty 20MP 7-in-1 Film to Digital Converter ...

"ISIS 'ranks' the women, considering foreign women and converts to be especially 'valuable.' "
"According to French journalist Anna Erelle’s recent exposé , ISIS foreign fighters prefer foreign women and converts because the jihadists find ...

Resources last updated: 12/17/2015 3:52:58 PM