Simple Conversion

The Converter class has ten overloaded Convert methods for converting from a byte array, file path, or URL as a string. Converting a file with no advanced options is straightforward. The following examples illustrate converting a file or URL to PDF followed by converting a string to PDF.

Converting a File or URL

This example demonstrates a simple file conversion from HTML (a specified URL) to PDF. The example also illustrates RTF to PDF conversion. The conversion process is similar for all 50 supported document types.

Use respective Converter classes for specific file types: WordConverter , ExcelConverter , PowerPointConverter , HtmlConverter , ImageConverter , RtfConverter, VisioConverter, or TextConverter if converting one of these file types.

Converter.Convert("http://www.google.com", pdfFilePath);
//OR
Converter.Convert(rtfFilePath, pdfFilePath);       
Converter.Convert("http://www.google.com", pdfFilePath)
'OR
Converter.Convert(rtfFilePath.rtf, pdfFilePath)      

HTML String Conversion

The following example demonstrates converting a specific HTML string to PDF (as opposed to using an actual HTML file or URL, as shown in the examples above).

Refer to the Converting Current Web Page to PDF section for an example of converting an online web page to PDF.

string sampleHtml = "<html><body><p>This is a very simple HTML string including a Table below.</p>" +  
                    "<h4>Two rows and three columns:</h4><table border=\"1\"><tr><td>100</td><td>200</td>" +  
                    "<td>300</td></tr><tr><td>400</td><td>500</td><td>600</td></tr></table></body></html>";  
Converter.ConvertHtmlString(sampleHtml, pdfFilePath); 
Dim sampleHtml As String = "<html><body><p>This is a very simple HTML string including a Table below.</p>" +   
                           "<h4>Two rows and three columns:</h4><table border=""1""><tr><td>100</td><td>200</td>" +   
                           "<td>300</td></tr><tr><td>400</td><td>500</td><td>600</td></tr></table></body></html>"  
Converter.ConvertHtmlString(sampleHtml, pdfFilePath)      

GitHub Project

Refer to the converter-dotnet-core example project on GitHub for examples using C# and Visual Basic with the specific converter classes rather than the Converter class. Each example also demonstrates using the class's conversion options.

C# Visual Basic
HtmlFileConversion.cs HtmlFileConversion.vb
JpegImageConversion.cs JpegImageConversion.vb
JpgImageConversion.cs JpgImageConversion.vb
GifImageConversion.cs GifImageConversion.vb
PngImageConversion.cs PngImageConversion.vb
TiffImageConversion.cs TiffImageConversion.vb
TextFileConversion.cs TextFileConversion.vb
DocFileConversion.cs DocFileConversion.vb

In this topic