一、下载C++ 电子邮件到 PDF 转换 API
要将电子邮件转换为 PDF,我们将使用适用于 C++ 的Aspose.Email和适用于 C++ API的 Aspose.Words 。前者是用于创建、操作和转换 Outlook 文件的本机 C++ 库。而后者允许您生成、修改和转换 Microsoft Word 文件。此外,它还支持将文件转换为 PDF 格式。我们将使用 Aspose.Email for C++ 加载电子邮件文件,并使用 Aspose.Words for C++ 将它们转换为 PDF 格式。您可以通过 NuGet 安装 API 或直接从下载部分下载它。
PM> Install-Package Aspose.Email.CppPM> Install-Package Aspose.Words.Cpp
二、使用 C++ 将电子邮件消息转换为 PDF
以下是使用 C++ 将电子邮件文件转换为 PDF 格式的步骤。
- 使用MailMessage类加载电子邮件文件。
- 将 MemoryStream 中的电子邮件消息另存为MHTML。
- 创建LoadOptions类的实例。
- 将加载格式设置为 MHTML。
- 使用Document类的Document(SharedPtr stream, SharedPtr loadOptions)构造函数从 MemoryStream 加载文件。
- 使用Document->Save(String fileName, SaveFormat saveFormat)方法将电子邮件保存为 PDF 文件。
以下代码示例显示如何将电子邮件消息转换为 PDF 格式。
// Source email fileSystem::String sampleFile = u"SourceDirectory\Message.msg";// Load email message using fileSystem::SharedPtr<Aspose::Email::MailMessage> msg = Aspose::Email::MailMessage::Load(sampleFile);// Create memory streamSystem::SharedPtr<System::IO::MemoryStream> stream = System::MakeObject<System::IO::MemoryStream>();// Save email message into memory streammsg->Save(stream, Aspose::Email::SaveOptions::get_DefaultMhtml());// Create load optionsSystem::SharedPtr<Aspose::Words::LoadOptions> loadOptions = System::MakeObject<Aspose::Words::LoadOptions>();// Set load formatloadOptions->set_LoadFormat(Aspose::Words::LoadFormat::Mhtml);// Create an instance of Document class and load the MTHML from MemoryStreamSystem::SharedPtr<Aspose::Words::Document> doc = System::MakeObject<Aspose::Words::Document>(stream, loadOptions);// Output file pathSystem::String outputPath = u"OutputDirectory\email-to-pdf.pdf";// Save email as PDFdoc->Save(outputPath, Aspose::Words::SaveFormat::Pdf);
以上便是使用 C++ 将电子邮件消息转换为 PDF详细步骤,要是您还有其他关于产品方面的问题,欢迎咨询我们,或者加入我们官方技术交流群。
欢迎下载|体验更多Aspose产品
点此获取更多Aspose产品信息 或 加入Aspose技术交流群()
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!