i need a code in c# so that i can convert webpages n html pages into PDF format

this is a community help forum. We help you with your problem, we don't do everything for you. Tell us what you have tried and what problems your are having and we will help you solve them. We won't do everything for you.

out there got alot PDF convertion DLL, if u need for non bunisess use.
Or u can export your file to excel format using .net and then using microsoft 2007 to convert it to PDF.

if you can wait till tomorrow i have code snippet that will perfectly work for you. See you tomorrow when i get to office

Hi,

Here is a .NET 2.0 library for html to pdf conversion: www.html-to-pdf.net.

Here is some code sample from their website:

PdfConverter pdfConverter = new PdfConverter();pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;pdfConverter.PdfDocumentOptions.ShowHeader = true;pdfConverter.PdfDocumentOptions.ShowFooter = true;pdfConverter.PdfDocumentOptions.LeftMargin = 5;pdfConverter.PdfDocumentOptions.RightMargin = 5;pdfConverter.PdfDocumentOptions.TopMargin = 5;pdfConverter.PdfDocumentOptions.BottomMargin = 5;pdfConverter.PdfDocumentOptions.UseMetafileFormat = true;pdfConverter.PdfDocumentOptions.ShowHeader = false;//pdfConverter.PdfHeaderOptions.HeaderText = "Sample header: " + TxtURL.Text;//pdfConverter.PdfHeaderOptions.HeaderTextColor = Color.Blue;//pdfConverter.PdfHeaderOptions.HeaderDescriptionText = string.Empty;//pdfConverter.PdfHeaderOptions.DrawHeaderLine = false;pdfConverter.PdfFooterOptions.FooterText = "Sample footer: " + TxtURL.Text + ". You can change color, font and other options";pdfConverter.PdfFooterOptions.FooterTextColor = Color.Blue;pdfConverter.PdfFooterOptions.DrawFooterLine = false;pdfConverter.PdfFooterOptions.PageNumberText = "Page";pdfConverter.PdfFooterOptions.ShowPageNumber = true;pdfConverter.LicenseFilePath = System.IO.Path.Combine(Server.MapPath("~"), "Bin");byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(url);System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;response.Clear();response.AddHeader("Content-Type", "binary/octet-stream");response.AddHeader("Content-Disposition", "attachment; filename=" + downloadName + "; size=" + downloadBytes.Length.ToString());response.Flush();response.BinaryWrite(downloadBytes);response.Flush();response.End();

See the original code sample here:
http://www.html-to-pdf.net/Support.aspx#csharp

Hi,

The new version 3.2.3 of the Winnovative HTML to PDF converter for .NET is now faster and has a lot of new features like CSS page breaks, live http links in PDF, keep together feature for any HTML element, password protection, embedded fonts, etc.
Here you can see all the HTML to PDF converter features. If you liked the version 2.x you'll love 3.2.3.

Regards,
Florin

hi all ...
is there any free dll for html to pdf conversion, to be used in asp.net 2.0 ?
which doesn't show any "Evaluation Version" message in the converted file ...
please help ..
thanks ..

hi ...

i tried this library, but this is giving some errors ...
pdfConverter.LicenseFilePath = System.IO.Path.Combine(Server.MapPath("~"), "Bin");
i suppose i am not having that licence ...

then what i did is, commented this piece of code ...
finally the file is generated as i wanted but with a message written in file as "Evaluation Version ..."

is there any other other method so that i can bypass the message of "Evaluation Version" in the generated pdf.

please help ...
thanks ...


Hi,

Here is a .NET 2.0 library for html to pdf conversion: www.html-to-pdf.net.

Here is some code sample from their website:

PdfConverter pdfConverter = new PdfConverter();pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;pdfConverter.PdfDocumentOptions.ShowHeader = true;pdfConverter.PdfDocumentOptions.ShowFooter = true;pdfConverter.PdfDocumentOptions.LeftMargin = 5;pdfConverter.PdfDocumentOptions.RightMargin = 5;pdfConverter.PdfDocumentOptions.TopMargin = 5;pdfConverter.PdfDocumentOptions.BottomMargin = 5;pdfConverter.PdfDocumentOptions.UseMetafileFormat = true;pdfConverter.PdfDocumentOptions.ShowHeader = false;//pdfConverter.PdfHeaderOptions.HeaderText = "Sample header: " + TxtURL.Text;//pdfConverter.PdfHeaderOptions.HeaderTextColor = Color.Blue;//pdfConverter.PdfHeaderOptions.HeaderDescriptionText = string.Empty;//pdfConverter.PdfHeaderOptions.DrawHeaderLine = false;pdfConverter.PdfFooterOptions.FooterText = "Sample footer: " + TxtURL.Text + ". You can change color, font and other options";pdfConverter.PdfFooterOptions.FooterTextColor = Color.Blue;pdfConverter.PdfFooterOptions.DrawFooterLine = false;pdfConverter.PdfFooterOptions.PageNumberText = "Page";pdfConverter.PdfFooterOptions.ShowPageNumber = true;pdfConverter.LicenseFilePath = System.IO.Path.Combine(Server.MapPath("~"), "Bin");byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(url);System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;response.Clear();response.AddHeader("Content-Type", "binary/octet-stream");response.AddHeader("Content-Disposition", "attachment; filename=" + downloadName + "; size=" + downloadBytes.Length.ToString());response.Flush();response.BinaryWrite(downloadBytes);response.Flush();response.End();

See the original code sample here:
http://www.html-to-pdf.net/Support.aspx#csharp

I use my all report in Html , I want to change the html report to pdf files (asp.net & C#)

can i get a code to convert .aspx page to pdf from another aspx page

Although this appears to be a zombie thread, I'm going to recommend iTextSharp which is free open source part of the iTextPdf library project.

If you look in their docs they have sample code to convert from HTML as well as building a PDF from scratch.

Could you please post a link with an example to converting html to pds using iTextSharp? i couldn't find any... thanks!!

Sorry couldn't find the initial example I used a couple months ago, was sure they had it in their official sample code somewhere but it goes something like this.

StringReader stringReader = new StringReader(htmlText.ToString());
Document doc = new Document(PageSize.A4);
List<iTextSharp.text.IElement> elements = 
    iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(stringReader, null);
doc.Open();
foreach (object item in elements)
{
    doc.Add((IElement)item);
}
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Close();

Codeproject and stackoverflow both have a bunch of posts covering this and other iText topics.
There is also the XMLParser classes (an update of the old HTMLparser class from iText) which is able to parse HTML5 to PDF but I haven't used this.

Also, here are some good tutorials I bookmarked for creating pdfs with iTextSharp.

Pelase try useing webreference of Microsoft Nuget and add a reference of PdfSharp. Which has a very rich and easy to handle functionality. By using it you can also create a PDF Document by your C# Code. I Used that into a project when i was new with that. Hope you will also get master in PDF Renderring by PDFSharf provided bu Microsoft Nuget.

If you need more help please have a look at the .Net WebReference and feel free to ask me. Waiting for your response.

You can find plenty of online softwares to convert your HTML code into PDF.

See this online post on pdf to html converting and the vice versa html to pdf tranforming, containing the sample codes using vb.net.

Public Sub ConvertPdftoHtml()
If True Then
    PDFInputFile = ("C:/1.pdf")
    PDFPageNumber = "1"
    HTMLOutputFile = OutputFormat.html
End If
End Sub
PDF.Save("OutputFormat.html", SaveFormat.Html)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.