HtmlToPdfConvert Method (String, String)
Writes an HTML or plain-text string into the file in PDF format.

Namespace: MailBee.Pdf
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public void Convert(
	string source,
	string pdfFile
)

Parameters

source
Type: SystemString
The input string containing HTML or plain-text data.
pdfFile
Type: SystemString
The filename to write .pdf data into.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptionsource or pdfFile is a null reference (Nothing in Visual Basic) or an empty string.
MailBeeStreamExceptionA stream error occurred.
MailBeeIOExceptionAn I/O error occurred.
Remarks

If SourceType is Html (default value), the input is considered HTML; if SourceType is Text the input is considered plain-text; otherwise, XMLized XHTML.

If your source is BodyHtmlText and the message contains embedded pictures, you need to save them first (like in the example below).

Examples
This example loads an e-mail from file (we assume it's HTML e-mail), saves all embedded pictures (if any) into a temporary folder it creates, then generates a PDF file and removes the temp folder.
using System;
using System.IO;
using MailBee;
using MailBee.Mime;
using MailBee.Pdf;
using MailBee.SmtpMail;

class Sample
{
    static void Main(string[] args)
    {
        MailMessage msg = new MailMessage();
        msg.LoadMessage(@"C:\Temp\source.eml");
        HtmlToPdf htmlConv = new HtmlToPdf();
        msg.Parser.WorkingFolder = Path.GetTempPath();
        try
        {
            string htmlWithRealImgLinks = msg.GetHtmlAndSaveRelatedFiles(null, VirtualMappingType.NonWeb,
                MessageFolderBehavior.CreateAndDelete);
            htmlConv.Convert(htmlWithRealImgLinks, @"C:\Temp\result.pdf");
        }
        finally
        {
            msg.Dispose();
        }
    }
}
See Also