Get PDF Document by Converting and Use C#/VB.NET to Convert HTML to PDF
It seems that PDF is taken as the best format to deliver electronic information because it can be used on any operation system platform. And in PDF, we can insert images, videos and flash. These contents can make a PDF document be more appealed.
People often create a new PDF document by converting from other format document, for example, Word, Excel and HTML. Actually, there is not a direct way to convert other format document to PDF. People need to use some tools. As is known, Adobe Acrobat is a professional tool to manipulate PDF. Also, there are some other small tools which specialize in converting. If people just want to convert one document to PDF, the PDF converters are more useful.
Besides using tools, programmers pay much attention on convert to PDFprogrammatically. On professional technology websites, we can find several articles about conversion from .NET. Some articles are very useful.
Recently, I discovered a good method about how to convert HTML to PDF with C# and VB.NET. Therefore, I want to share it with you.
In this method, one third party add-in is used, Spire.Doc.
C#
using System;
using Spire.Pdf;
namespace FromHTML
{
class Program
{
[STAThread]
static void Main(string[] args)
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
String url = "http://www.e-iceblue.com/";
doc.LoadFromHTML(url, false, true, true);
//Save pdf file.
doc.SaveToFile("FromHTML.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("FromHTML.pdf");
}
}
}
VB.NET
Imports Spire.Pdf
Namespace FromHTML
Friend Class Program
Shared Sub Main(ByVal args() As String)
'Create a pdf document.
Dim doc As New PdfDocument()
Dim url As String = "http://www.e-iceblue.com/"
doc.LoadFromHTML(url, False, True, True)
'Save pdf file.
doc.SaveToFile("FromHTML.pdf")
doc.Close()
'Launching the Pdf file.
Process.Start("FromHTML.pdf")
End Sub
End Class
End Namespace
What’s more, I discovered a new PDF converter which can be used to convert Word, Excel, HTML and other format to PDF. Also, during conversion, the document can be encrypted or added watermark. Now, the developer just releases the beta version. If you are interested in it, you can learn something from here.
|