How to generate PDF files from HTML files FOR FREE

2 views
Skip to first unread message

SalvaMalaga

unread,
Nov 24, 2009, 7:47:47 AM11/24/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hello, does anybody knows any method to generate .pdf files from html
files for FREE

I have tried with itextsharp library with the code:

Document document = new Document(PageSize.A4, 80, 50, 30,
65);
PdfWriter.GetInstance(document, new FileStream(“file.pdf”,
FileMode.Create));
Document.Open();
HtmlParser.Parse (document, “newfile.htm”);
Document.Close();

The thing is that i am getting the PDF file BUT this library is so
strict that i am missing the biggest part of the information in the
HTML file, so i had to delete lots of information. I cant afford this
because i am using templates and they are generating quite complex
html files.

So , again, does anybody know how to generate pdf from html??? i dont
need to phisically generate the file, i just need to print id in the
screen. For this i also tried this:

Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=Test.pdf");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "Application/pdf";


StringWriter sw1 = new StringWriter();
sw1.Write("<html><p align='center'>Hello World!</p></
html>");
//StreamWriter sw1 = File.CreateText(@"c:\temp
\ResortInformation.htm");
HtmlTextWriter htmlWrite = new HtmlTextWriter(sw1);
Page.RenderControl(htmlWrite);
Response.Write(sw1.ToString());
Response.End();


but does not work again...

If i change it to WORD format, it works, generating the right html
info (without html tags) but i need pdf not word...

Thanks in advance mates !!!

Budi Sentosa

unread,
Nov 25, 2009, 2:00:26 AM11/25/09
to dotnetde...@googlegroups.com

Google for itextsharp

Reply all
Reply to author
Forward
0 new messages