How to Convert Html to PDF in C#.NET Code
iDiTect .NET Converter SDK is one of the best C# HTML to PDF converter libraries for .NET programming using in Winforms and ASP.NET application. Creating PDF document from html file(local or web url) easily with major features used in HTML5 and CSS/CSS3. Please note, Pseudo-classes selectors in CSS is not support now.
Converting Html to PDF with PDF or PDF/A compliance level, all html tags are support, such as images, table, links, lists, paragraphes and so on.
How to Convert Html File to PDF in C# language
Creating PDF from local html file, import html content and image/style from embedded and external folders. Or creating PDF from online page, developers need download web page content from web url, like using "WebClient", save web page to bytes or stream, and then convert them to PDF document in C#.NET.
HtmlToPdfConverter converter = new HtmlToPdfConverter();
//Load html from stream
using (Stream stream = File.OpenRead("sample.html"))
{
converter.Load(stream);
}
//Choose pdf compliance level, PDF or PDF/A
converter.PdfStandard = PdfStandard.Pdf;
//Convert html to pdf, and save it to file stream
using (var stream = File.OpenWrite("convert.pdf"))
{
converter.Save(stream);
}
How to Convert Html Elements to PDF in C# language
Creating PDF from html tags and elements. Write text content embed to html elements, such as
,
HtmlToPdfConverter converter = new HtmlToPdfConverter();
//Define the css for the html content
converter.DefaultStyleSheet = ".para{font-size: 24px; color: #FF0000;}";
string htmlContent = "
Content with special style.
Content without style
";converter.Load(htmlContent);
//Choose pdf compliance level, PDF or PDF/A
converter.PdfStandard = PdfStandard.Pdf;
File.WriteAllBytes("convert.pdf", converter.SaveAsBytes());
What iDiTect .NET Document component can doWe provide powerful & profession document & image controls: Add a text watermark on PDF in C# add image & text-based watermark to documents. PDF to Image, Jpeg, multipage TIFF, PNG in C# and VB.Net PDF to Image Converter Library is a professional PDF to image converter solution for .NET, C#, VB windows and ASP.NET. How to convert .jpg file into .pdf using c# the best way to convert a GIF or JPG image to PDF in c# How to extract text from a Microsoft Word document in C# Please refer to the following section of the documentation which outlines everything you need to know about extracting Text from document. How to Convert RTF to PDF in C# effortlessly convert RTF to PDF in your application within this section, enables you to directly load file with .rtf entension and then convert RTF to PDF. Convert RTF and TXT files into DOCX files in C# Add a paragraph to the section in the Word document, declare a String variable to store the RTF string.