HtmlToPdfConvert Method (String, Stream)
Writes an HTML or plain-text string into a stream in PDF format.

Namespace: MailBee.Pdf
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public void Convert(
	string source,
	Stream outputStream
)

Parameters

source
Type: SystemString
The input string containing HTML or plain-text data.
outputStream
Type: System.IOStream
The output stream to write .pdf data into.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptionsource or outputStream 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();
        FileStream fsPdf = new FileStream(@"C:\Temp\result.pdf", FileMode.Create);
        msg.Parser.WorkingFolder = System.IO.Path.GetTempPath();
        try
        {
            string htmlWithRealImgLinks = msg.GetHtmlAndSaveRelatedFiles(null, VirtualMappingType.NonWeb,
                MessageFolderBehavior.CreateAndDelete);
            htmlConv.Convert(htmlWithRealImgLinks, fsPdf);
        }
        finally
        {
            fsPdf.Close();
            msg.Dispose();
        }
    }
}
See Also