在本教程中,我们将学习如何使用 C++** 将 Xsl Fo 渲染为 PDF 文件。 Xsl Fo 文件包含 XML 样式表格式,用于通过 C++ 中的一些简单 API 调用生成 PDF 文件。该功能不需要在 Windows 或 Linux 平台上安装 Adobe Acrobat 或任何应用程序。
使用 C++ 将 Xsl Fo 渲染为 PDF 文件的步骤
- 从 NuGet 包管理器安装 Aspose.Pdf for C++ 库
- 添加对 Aspose::Pdf 命名空间的引用
- 初始化 XslFoLoadOptions 类的对象以加载输入文件
- 使用 Document 类加载输入 Xsl Fo 文件
- 使用 Save 方法将 Xsl Fo 转换为 PDF 文件
您可以通过几行代码使用 C++* 将 Xsl Fo 转换为 PDF 文件。它可以使用 XslFoLoadOptions 对象有效地使用 C++* 生成 Xsl Fo 到 PDF 文件。
使用 C++ 将 Xsl Fo 渲染为 PDF 文件的代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <iostream> | |
#include <system/smart_ptr.h> | |
#include <Aspose.PDF.Cpp/License.h> | |
#include <Aspose.PDF.Cpp/Document.h> | |
#include <Aspose.PDF.Cpp/XslFoLoadOptions.h> | |
using namespace System; | |
using namespace Aspose::Pdf; | |
class XSLFOEx { | |
public: | |
static void ConvertXslFo() | |
{ | |
// Set the license for Aspose.PDF for CPP to create PDF from XSL FO file | |
SharedPtr<License> XSLFOtoPDFLicense = System::MakeObject<License>(); | |
XSLFOtoPDFLicense->SetLicense(u"Aspose.PDF.NET.lic"); | |
// Create an instance of the XslFoLoadOptions class | |
SharedPtr<XslFoLoadOptions> options = MakeObject<XslFoLoadOptions>(); | |
// Load the input XSL FO file | |
SharedPtr<Document> InputXSLFODocument = MakeObject<Document>(u"InputXSLFODocument.fo", options); | |
// Save the XSL FO document as PDF file | |
InputXSLFODocument->Save(u"OutputPDFConvertedFromXSLFOFile.pdf"); | |
} | |
}; |
在上一主题中,我们学习了 如何使用 C++ 读取 PDF 文件中的书签。本主题介绍如何使用 C++ 将 Xsl Fo 导出为 PDF 文件。