HtmlToPdfConvert Method (String, Stream) |
Namespace: MailBee.Pdf
Exception | Condition |
---|---|
MailBeeInvalidArgumentException | source or outputStream is a null reference (Nothing in Visual Basic) or an empty string. |
MailBeeStreamException | A stream error occurred. |
MailBeeIOException | An I/O error occurred. |
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).
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(); } } }