The coding instructions are formulated to help you to try-out the features without the requirement to write your own code. ByteScout Premium Suite is the bundle that includes twelve SDK products from ByteScout including tools and components for PDF, barcodes, spreadsheets, screen video recording. It can be applied to convert text email to pdf with pdf sdk using VB.NET.
This prolific sample source code in VB.NET for ByteScout Premium Suite contains various functions and other necessary options you should do calling the API to convert text email to pdf with pdf sdk. Follow the instructions from scratch to work and copy the VB.NET code. If you want to use these VB.NET sample examples in one or many applications then they can be used easily.
Trial version of ByteScout Premium Suite is available for free. Source code samples are included to help you with your VB.NET app.
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
Imports System.Drawing.Printing
Imports System.Linq
Imports System.Text
Imports Bytescout.PDF
Imports Bytescout.PDF.Converters
Module Program
Sub Main()
Try
Console.WriteLine("Please wait while PDF is being created...")
' Parse MessageContents using MsgReader Library
' MsgReader library can be obtained from: https://github.com/Sicos1977/MSGReader
Using msg = New MsgReader.Outlook.Storage.Message("TxtSampleEmail.msg")
' Get Sender information
Dim from = msg.GetEmailSender(False, False)
' Message sent datetime
Dim sentOn = msg.SentOn
' Recipient To information
Dim recipientsTo = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.[To], False, False)
' Recipient CC information
Dim recipientsCc = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.Cc, False, False)
' Recipient BCC information
Dim recipientBcc = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.Bcc, False, False)
Dim oHtmlGenerator As HtmlGenerator = New HtmlGenerator()
oHtmlGenerator.Title = {code}quot;Subject: {msg.Subject}"
oHtmlGenerator.AddParagraphBodyItem({code}quot;File Name: {msg.FileName}")
oHtmlGenerator.AddParagraphBodyItem({code}quot;From: {from}")
oHtmlGenerator.AddParagraphBodyItem({code}quot;Sent On: {(If(sentOn.HasValue, sentOn.Value.ToString("MM/dd/yyyy HH:mm"), ""))}")
oHtmlGenerator.AddParagraphBodyItem({code}quot;To: {recipientsTo}")
oHtmlGenerator.AddParagraphBodyItem({code}quot;Subject: {msg.Subject}")
If Not String.IsNullOrEmpty(recipientsCc) Then
oHtmlGenerator.AddParagraphBodyItem({code}quot;CC: {recipientsCc}")
End If
If Not String.IsNullOrEmpty(recipientBcc) Then
oHtmlGenerator.AddParagraphBodyItem({code}quot;BCC: {recipientBcc}")
End If
oHtmlGenerator.AddRawBodyItem("<hr/>")
Dim msgBodySplitted = msg.BodyText.Split(vbLf.ToCharArray())
For Each itmBody In msgBodySplitted
oHtmlGenerator.AddParagraphBodyItem(itmBody)
Next
oHtmlGenerator.SaveHtml("result.html")
Using converter As HtmlToPdfConverter = New HtmlToPdfConverter()
converter.PageSize = PaperKind.A4
converter.Orientation = Bytescout.PDF.Converters.PaperOrientation.Portrait
converter.ConvertHtmlToPdf("result.html", "result.pdf")
Dim processStartInfo As ProcessStartInfo = New ProcessStartInfo("result.pdf")
processStartInfo.UseShellExecute = True
Process.Start(processStartInfo)
End Using
End Using
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.WriteLine("Press enter key to exit...")
Console.ReadLine()
End Try
End Sub
''' <summary>
''' Html Generator class
''' </summary>
Class HtmlGenerator
#Region "Constructors and variable declarations"
Public Sub New()
Me.StrBodyItems = New List(Of String)()
End Sub
Public Property Title As String
Private Property StrBodyItems As List(Of String)
#End Region
#Region "Methods"
''' <summary>
''' Add Body Item
''' </summary>
Public Sub AddRawBodyItem(ByVal strBodyItem As String)
StrBodyItems.Add(strBodyItem)
End Sub
''' <summary>
''' Add Paragraph body item
''' </summary>
Public Sub AddParagraphBodyItem(ByVal strText As String)
StrBodyItems.Add(String.Format("<p style=''>{0}</p>", strText))
End Sub
''' <summary>
''' Gets generated HTML
''' </summary>
Public Function GetHtml() As String
Dim oRetHtml As StringBuilder = New StringBuilder(String.Empty)
oRetHtml.Append("<html>")
oRetHtml.Append("<head>")
oRetHtml.AppendFormat("<title>{0}</title>", Title)
oRetHtml.Append("<style>p {
line-height: 107.9 %;
margin-bottom: 13pt;
font-family: 'Arial', 'sans-serif';
font-size: 15pt;
margin-top: 0;
margin-left: 0;
margin-right: 0;
}</style>")
oRetHtml.Append("</head>")
oRetHtml.Append("<body>")
For Each itemBody In StrBodyItems
oRetHtml.Append(itemBody)
Next
oRetHtml.Append("</body>")
oRetHtml.Append("</html>")
Return oRetHtml.ToString()
End Function
''' <summary>
''' Save all HTML
''' </summary>
Public Sub SaveHtml(ByVal fileName As String)
Dim allHtml = GetHtml()
System.IO.File.WriteAllText(fileName, allHtml)
End Sub
#End Region
End Class
End Module
60 Day Free Trial or Visit ByteScout Premium Suite Home Page
Explore ByteScout Premium Suite Documentation
Explore Samples
Sign Up for ByteScout Premium Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MsgReader" version="3.4.1" targetFramework="net45" />
<package id="OpenMcdf" version="2.2.1.3" targetFramework="net45" />
</packages>
60 Day Free Trial or Visit ByteScout Premium Suite Home Page
Explore ByteScout Premium Suite Documentation
Explore Samples
Sign Up for ByteScout Premium Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout Premium Suite Home Page
Explore ByteScout Premium Suite Documentation
Explore Samples
Sign Up for ByteScout Premium Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
also available as: