PyMuPDF 1.24.4 中文文档(十一)(4)

简介: PyMuPDF 1.24.4 中文文档(十一)

PyMuPDF 1.24.4 中文文档(十一)(3)https://developer.aliyun.com/article/1559463


一些示例

使用数字进行操作

对于通常的算术操作,数字始终允许作为第二个操作数。此外,您可以制定 "x in OBJ",其中 x 是一个数字。它实现为 "x in tuple(OBJ)"

>>> pymupdf.Rect(1, 2, 3, 4) + 5
pymupdf.Rect(6.0, 7.0, 8.0, 9.0)
>>> 3 in pymupdf.Rect(1, 2, 3, 4)
True
>>> 

创建文档页面矩形的左上角四分之一:

>>> page.rect
Rect(0.0, 0.0, 595.0, 842.0)
>>> page.rect / 2
Rect(0.0, 0.0, 297.5, 421.0)
>>> 

以下将提供连接两点 p1p2 的线的中点

>>> p1 = pymupdf.Point(1, 2)
>>> p2 = pymupdf.Point(4711, 3141)
>>> mp = (p1 + p2) / 2
>>> mp
Point(2356.0, 1571.5)
>>> 

使用“类似”对象进行操作

二元操作的第二个操作数始终可以“类似”于左操作数。在此上下文中,“类似”表示“具有相同长度的数字序列”。使用上述示例:

>>> p1 + p2
Point(4712.0, 3143.0)
>>> p1 + (4711, 3141)
Point(4712.0, 3143.0)
>>> p1 += (4711, 3141)
>>> p1
Point(4712.0, 3143.0)
>>> 

要将矩形向右移动 5 个像素,请执行以下操作:

>>> pymupdf.Rect(100, 100, 200, 200) + (5, 0, 5, 0)  # add 5 to the x coordinates
Rect(105.0, 100.0, 205.0, 200.0)
>>> 

点、矩形和矩阵可以使用矩阵进行变换。在 PyMuPDF 中,我们将其视为**“乘法”(或“除法”**),其中第二个操作数可以“类似”于矩阵。在此上下文中,“除法”表示“与倒置矩阵的乘法”:

>>> m = pymupdf.Matrix(1, 2, 3, 4, 5, 6)
>>> n = pymupdf.Matrix(6, 5, 4, 3, 2, 1)
>>> p = pymupdf.Point(1, 2)
>>> p * m
Point(12.0, 16.0)
>>> p * (1, 2, 3, 4, 5, 6)
Point(12.0, 16.0)
>>> p / m
Point(2.0, -2.0)
>>> p / (1, 2, 3, 4, 5, 6)
Point(2.0, -2.0)
>>>
>>> m * n  # matrix multiplication
Matrix(14.0, 11.0, 34.0, 27.0, 56.0, 44.0)
>>> m / n  # matrix division
Matrix(2.5, -3.5, 3.5, -4.5, 5.5, -7.5)
>>>
>>> m / m  # result is equal to the Identity matrix
Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
>>>
>>> # look at this non-invertible matrix:
>>> m = pymupdf.Matrix(1, 0, 1, 0, 1, 0)
>>> ~m
Matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
>>> # we try dividing by it in two ways:
>>> p = pymupdf.Point(1, 2)
>>> p * ~m  # this delivers point (0, 0):
Point(0.0, 0.0)
>>> p / m  # but this is an exception:
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
  p / m
  File "... /site-packages/fitz/pymupdf.py", line 869, in __truediv__
  raise ZeroDivisionError("matrix not invertible")
ZeroDivisionError: matrix not invertible
>>> 

作为特殊情况,矩形支持附加的二元操作:

  • 交集 – 矩形类的公共区域,操作符 “&”
  • 包含 – 扩展以包含点状或矩形状,操作符 “|”
  • 包含检查 – 点状或矩形状是否在内部

这是一个创建包围给定点的最小矩形的示例:

>>> # first define some point-likes
>>> points = []
>>> for i in range(10):
 for j in range(10):
 points.append((i, j))
>>>
>>> # now create a rectangle containing all these 100 points
>>> # start with an empty rectangle
>>> r = pymupdf.Rect(points[0], points[0])
>>> for p in points[1:]:  # and include remaining points one by one
 r |= p
>>> r  # here is the to be expected result:
Rect(0.0, 0.0, 9.0, 9.0)
>>> (4, 5) in r  # this point-like lies inside the rectangle
True
>>> # and this rect-like is also inside
>>> (4, 4, 5, 5) in r
True
>>> 

您对本页有何反馈?


本软件按“原样”提供,不提供任何明示或暗示的担保。本软件在许可下分发,并且除非在该许可条款明确授权下,否则不得复制、修改或分发。请参阅 artifex.com 上的许可信息或联系美国加利福尼亚州旧金山 Mesa 街 39 号 108A 室的 Artifex Software Inc. 获取更多信息。

此文档涵盖了所有版本,直至 1.24.4。


使用数字进行操作

对于通常的算术操作,数字始终允许作为第二个操作数。此外,您可以制定 "x in OBJ",其中 x 是一个数字。它实现为 "x in tuple(OBJ)"

>>> pymupdf.Rect(1, 2, 3, 4) + 5
pymupdf.Rect(6.0, 7.0, 8.0, 9.0)
>>> 3 in pymupdf.Rect(1, 2, 3, 4)
True
>>> 

创建文档页面矩形的左上角四分之一:

>>> page.rect
Rect(0.0, 0.0, 595.0, 842.0)
>>> page.rect / 2
Rect(0.0, 0.0, 297.5, 421.0)
>>> 

以下将提供连接两点 p1p2 的线的中点

>>> p1 = pymupdf.Point(1, 2)
>>> p2 = pymupdf.Point(4711, 3141)
>>> mp = (p1 + p2) / 2
>>> mp
Point(2356.0, 1571.5)
>>> 

使用“类似”对象进行操作

二元操作的第二个操作数始终可以“类似”于左操作数。在此上下文中,“类似”表示“具有相同长度的数字序列”。使用上述示例:

>>> p1 + p2
Point(4712.0, 3143.0)
>>> p1 + (4711, 3141)
Point(4712.0, 3143.0)
>>> p1 += (4711, 3141)
>>> p1
Point(4712.0, 3143.0)
>>> 

要将矩形向右移动 5 个像素,请执行以下操作:

>>> pymupdf.Rect(100, 100, 200, 200) + (5, 0, 5, 0)  # add 5 to the x coordinates
Rect(105.0, 100.0, 205.0, 200.0)
>>> 

点、矩形和矩阵可以通过矩阵进行转换。在 PyMuPDF 中,我们将其视为**“乘法”(或“除法”**),其中第二个操作数可能“类似”于一个矩阵。在这种情况下,“除法”意味着“乘以倒置矩阵”:

>>> m = pymupdf.Matrix(1, 2, 3, 4, 5, 6)
>>> n = pymupdf.Matrix(6, 5, 4, 3, 2, 1)
>>> p = pymupdf.Point(1, 2)
>>> p * m
Point(12.0, 16.0)
>>> p * (1, 2, 3, 4, 5, 6)
Point(12.0, 16.0)
>>> p / m
Point(2.0, -2.0)
>>> p / (1, 2, 3, 4, 5, 6)
Point(2.0, -2.0)
>>>
>>> m * n  # matrix multiplication
Matrix(14.0, 11.0, 34.0, 27.0, 56.0, 44.0)
>>> m / n  # matrix division
Matrix(2.5, -3.5, 3.5, -4.5, 5.5, -7.5)
>>>
>>> m / m  # result is equal to the Identity matrix
Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
>>>
>>> # look at this non-invertible matrix:
>>> m = pymupdf.Matrix(1, 0, 1, 0, 1, 0)
>>> ~m
Matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
>>> # we try dividing by it in two ways:
>>> p = pymupdf.Point(1, 2)
>>> p * ~m  # this delivers point (0, 0):
Point(0.0, 0.0)
>>> p / m  # but this is an exception:
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
  p / m
  File "... /site-packages/fitz/pymupdf.py", line 869, in __truediv__
  raise ZeroDivisionError("matrix not invertible")
ZeroDivisionError: matrix not invertible
>>> 

作为特殊功能,矩形支持额外的二元操作:

  • 交集 – 矩形类的公共区域,操作符 “&”
  • 包含 – 扩展以包含一个点或矩形,操作符 “|”
  • 包含性检查 – 检查一个点或矩形是否在内部

这里是创建包围给定点的最小矩形的示例:

>>> # first define some point-likes
>>> points = []
>>> for i in range(10):
 for j in range(10):
 points.append((i, j))
>>>
>>> # now create a rectangle containing all these 100 points
>>> # start with an empty rectangle
>>> r = pymupdf.Rect(points[0], points[0])
>>> for p in points[1:]:  # and include remaining points one by one
 r |= p
>>> r  # here is the to be expected result:
Rect(0.0, 0.0, 9.0, 9.0)
>>> (4, 5) in r  # this point-like lies inside the rectangle
True
>>> # and this rect-like is also inside
>>> (4, 4, 5, 5) in r
True
>>> 

对本页有任何反馈吗?


此软件按原样提供,没有任何明示或暗示的保证。此软件根据许可分发,并且未经明确授权不得复制、修改或分发。请参阅许可信息,位于 artifex.com 或联系美国加利福尼亚州旧金山 Mesa 街 39 号 108A 室的 Artifex Software Inc. 获取更多信息。

此文档涵盖了所有版本直到 1.24.4。


低级功能和类

原文:pymupdf.readthedocs.io/en/latest/lowlevel.html

包含多个供有经验用户使用的功能和类。用于特殊需求或性能要求。

  • 功能
  • 设备
  • 共同工作:DisplayList 和 TextPage

你对本页面有任何反馈吗?


此软件按原样提供,不提供任何明示或暗示的保证。此软件在许可下分发,未经许可明确授权,不得复制、修改或分发。请参阅artifex.com上的许可信息或联系美国旧金山 CA 94129 Mesa Street 39 号 108A 套房的 Artifex Software Inc.以获取更多信息。

此文档涵盖了所有版本直至 1.24.4。


PyMuPDF 1.24.4 中文文档(十一)(5)https://developer.aliyun.com/article/1559465

相关文章
|
XML 数据安全/隐私保护 数据格式
PyMuPDF 1.24.4 中文文档(七)(3)
PyMuPDF 1.24.4 中文文档(七)
489 0
|
Linux iOS开发 MacOS
PowerShell命令行输出和添加系统环境变量
主要介绍使用PowerShell命令如何查看、修改和删除系统环境变量,对于需要操作添加PATH环境变量非常实用 。由于 Powershell 的跨平台,其环境变量修改可以在linux、macos...
5944 0
PowerShell命令行输出和添加系统环境变量
|
6月前
|
Linux 数据安全/隐私保护 虚拟化
虚拟机安装(CentOS7)
准备CentOS7镜像及VMware Workstation虚拟机工具,可从提供链接下载。使用百度云资源或自行获取安装包,在电脑上创建新虚拟机,参照指定教程完成安装。默认登录用户为root,密码由用户自设。
|
存储 文字识别 自然语言处理
PyMuPDF 1.24.4 中文文档(五)(2)
PyMuPDF 1.24.4 中文文档(五)
486 3
|
数据采集 人工智能 测试技术
Python有哪些好用且实用的Web框架?
Python 是一门功能强大的编程语言,在多个领域中得到广泛应用,包括爬虫、人工智能、游戏开发、自动化测试和 Web 开发。在 Web 开发中,Python 提供了多种框架以提高效率。以下是几个常用的 Python Web 框架:1) Django:开源框架,支持多种数据库引擎,适合新手;2) Flask:轻量级框架,基于简单核心并通过扩展增加功能;3) Web2py:免费开源框架,支持快速开发;4) Tornado:同时作为 Web 服务器和框架,适合高并发场景;5) CherryPy:简单易用的框架,连接 Web 服务器与 Python 代码。这些框架各有特色,可根据需求选择合适的工具。
711 14
|
11月前
|
机器学习/深度学习 人工智能 程序员
MiniMind:3小时训练26MB微型语言模型,开源项目助力AI初学者快速入门
在大型语言模型(LLaMA、GPT等)日益流行的今天,一个名为MiniMind的开源项目正在AI学习圈内引起广泛关注。项目让初学者能够在3小时内从零开始训练出一个仅26.88MB大小的微型语言模型。
777 1
|
XML 文字识别 前端开发
PyMuPDF 1.24.4 中文文档(十一)(5)
PyMuPDF 1.24.4 中文文档(十一)
665 0
|
XML 存储 数据安全/隐私保护
PyMuPDF 1.24.4 中文文档(五)(4)
PyMuPDF 1.24.4 中文文档(五)
518 0
|
Python
Python 中的 spell checker 库
Python 中的 spell checker 库
651 1
|
XML 编解码 文字识别
PyMuPDF 1.24.4 中文文档(八)(4)
PyMuPDF 1.24.4 中文文档(八)
1048 1