Aspose.Total for C++ 文件格式自动化库允许 C++ 开发人员通过两个简单的步骤将 PDF 转换为 MHTML。首先,您可以使用 Aspose.PDF for C++ API 将 PDF 文件格式转换为 DOC。其次,通过使用高级 Word 文档处理 API Aspose.Words for C++ ,您可以将 DOC 导出到 MHTML。
将 PDF 渲染为 MHTML 的 C++ API
转换要求
从命令行安装为 nuget install Aspose.Total.Cpp
或通过 Visual Studio 的包管理器控制台使用 ```Install-Package Aspose.Total.Cpp``。
或者,从 下载 获取 ZIP 文件中的离线 MSI 安装程序或 DLL。
// load PDF file with an instance of Document class reference
auto doc = MakeObject<Document>(u"sourceFile.pdf");
// save PDF as a DOC
doc->Save(u"DocOutput.doc", SaveFormat::Doc);
// load DOC with an instance of Document
System::SharedPtr<Document> wordDoc = System::MakeObject<Document>(u"DocOutput.doc");
// save document as Mhtml
wordDoc->Save(u"output.Mhtml");
通过 C++ 更改 PDF 文档的密码
在将 PDF 渲染为 MHTML 的过程中,您可以打开受密码保护的 PDF 并更改其密码。要更改 PDF 文件的密码,您必须知道该文档的所有者密码。您可以通过指定所有者密码并使用 ChangePasswords 方法更改密码来使用 Aspose.PDF for C++ 加载受密码保护的 PDF 文档。
// load an existing PDF Document
auto doc = MakeObject<Document>(L"input.pdf", L"owner");
// change password of PDF Document
doc->ChangePasswords(L"owner", L"newuser", L"newuser");
// save the document
doc->Save(L"output.Doc");
通过 C++ 限制 MHTML 文件编辑
您还可以使用 Aspose.Words for C++ API 限制 MHTML 文件编辑。有时您可能需要限制编辑文档的能力,只允许对其进行某些操作。 API 使您能够使用 ProtectionType 枚举参数来控制限制内容的方式。下面的代码示例演示了如何限制在文档中的编辑,以便只能在表单域中进行编辑。
// load Doc with an instance of Document
auto doc = System::MakeObject<Document>("input.doc");
// document protection only works when document protection is turned and only editing in form fields is allowed.
doc->Protect(ProtectionType::AllowOnlyFormFields, u"password");
// save the protected document.
doc->Save(u"Protected.Mhtml");