HtmlViewOptions 类属性允许您控制转换过程,更多信息请参阅此处。 例如,您可以将所有外部资源嵌入输出的 HTML 文件,压缩输出文件,并对其进行打印优化。
Python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions
def render_docx_to_html():
# 实例化 Viewer
with Viewer("resume.docx") as viewer:
# 设置输出 HTML 选项,每页一个文件
view_options = HtmlViewOptions.for_embedded_resources("page_{0}.html")
# 将 DOCX 渲染为带嵌入资源的 HTML
viewer.view(view_options)
if __name__ == "__main__":
render_docx_to_html()
创建 PdfViewOptions 类实例并将其传递给 Viewer.view 方法,以将 PowerPoint PPTX 文件转换为 PDF。 PdfViewOptions 类属性允许您控制转换过程。例如,您可以保护输出的 PDF 文件、重新排序其页面,并指定文档图像的质量。详情请参阅以下文档章节。
Python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions
def export_pptx_to_pdf():
# 实例化 Viewer
with Viewer("presentation.pptx") as viewer:
# 设置输出 PDF 选项
view_options = PdfViewOptions("presentation.pdf")
# 将 PPTX 导出为 PDF
viewer.view(view_options)
if __name__ == "__main__":
export_pptx_to_pdf()
创建 PngViewOptions 实例并将其传递给 Viewer.view 方法,以将 DOCX 文档的每一页渲染为单独的 PNG 图像。 输出路径中的 {0} 占位符会被页面编号替换,因此多页文档会为每页生成一个 PNG。更多渲染示例请参阅快速入门指南。
Python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PngViewOptions
def render_docx_to_png():
# 实例化 Viewer
with Viewer("resume.docx") as viewer:
# 设置输出 PNG 选项,每页一张图像
view_options = PngViewOptions("page_{0}.png")
# 将 DOCX 渲染为 PNG 图像
viewer.view(view_options)
if __name__ == "__main__":
render_docx_to_png()