DocumentWriter#

This class is for PDF only.

  • v1.21.0 中新增

该类表示一个实用工具,可输出各种 PyMuPDF 支持的文档类型

PyMuPDF 中,该类仅用于输出 PDF 文档,其页面由 Story DOM 填充。

未来可能会使用 DocumentWriter 处理其他文档类型。

方法 / 属性

简要描述

DocumentWriter.begin_page()

开始一个新的输出页面

DocumentWriter.end_page()

结束当前输出页面

DocumentWriter.close()

刷新待处理的输出并关闭文件

类 API

class DocumentWriter#
__init__(self, path, options=None)#

创建一个文档写入对象,传入一个 Python 文件指针或文件路径。还可以传递用于保存文件的选项。

此类还可作为 Python 上下文管理器使用。

参数:
  • path

    输出文件。可以是字符串文件名,也可以是任意 Python 文件指针。

    备注

    通过使用 io.BytesIO() 对象作为文件指针,文档写入器可以在内存中创建 PDF。随后,该 PDF 可以重新打开用于输入并进一步操作。该技术在 Stories 配方 中的多个示例脚本中有所应用。

  • options (str) – 指定输出 PDF 的保存选项。常见选项包括 “compress” 或 “clean”。更多可能的选项可参考 mutool convert CLI 工具的帮助输出。

begin_page(mediabox)#

启动一个给定尺寸的新输出页面。

参数:

mediabox (rect_like) – 指定页面大小的矩形。调用此方法后,输出操作可以向页面写入内容。

end_page()#

结束当前页面。该方法会刷新所有待处理的数据,并将页面追加到输出文档中。

close()#

关闭输出文件。调用此方法后,所有待处理的数据都会被写入。

具体用法示例,请参考 Story 章节。

  • New in v1.21.0

This class represents a utility which can output various document types supported by PyMuPDF.

In PyMuPDF only used for outputting PDF documents whose pages are populated by Story DOMs.

Using DocumentWriter also for other document types might happen in the future.

Method / Attribute

Short Description

DocumentWriter.begin_page()

start a new output page

DocumentWriter.end_page()

finish the current output page

DocumentWriter.close()

flush pending output and close the file

Class API


本软件按原样提供,不作任何明示或暗示担保。本软件根据许可分发,除非根据该许可条款明确授权,否则不得复制、修改或分发。请参阅 artifex.com 上的许可信息,或联系 Artifex Software Inc., 39 Mesa Street, Suite 108A, San Francisco CA 94129, United States 了解更多信息。