You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:arg rect_like,quad_like,list,tuple quads: *(Changed in v1.14.20)* the rectangles or quads containing the to-be-marked text (locations). A list or tuple must consist of :data:`rect_like` or :data:`quad_like` items (or even a mixture of either). You should prefer using quads, because this will automatically support non-horizontal text and avoid rectangle-to-quad conversion effort. *(Changed in v1.16.14)* **Set this parameter to** *None* if you want to use the following arguments.
272
+
:arg rect_like,quad_like,list,tuple quads: *(Changed in v1.14.20)* the location(s) -- rectangle(s) or quad(s) -- to be marked. A list or tuple must consist of :data:`rect_like` or :data:`quad_like` items (or even a mixture of either). Every item must be finite, convex and not empty (as applicable). *(Changed in v1.16.14)* **Set this parameter to** *None* if you want to use the following arguments.
273
273
:arg point_like start: *(New in v1.16.14)* start text marking at this point. Defaults to the top-left point of *clip*.
274
274
:arg point_like stop: *(New in v1.16.14)* stop text marking at this point. Defaults to the bottom-right point of *clip*.
275
275
:arg rect_like clip: *(New in v1.16.14)* only consider text lines intersecting this area. Defaults to the page rectangle.
@@ -797,16 +797,16 @@ In a nutshell, this is what you can do with PyMuPDF:
797
797
798
798
*Changed in version 1.17.0:*
799
799
800
-
* The method should deliver mostly correct results now.
800
+
* The method should deliver correct results now.
801
801
* The page's ``/Contents`` are no longer modified by this method.
802
-
* Images occurring inside embedded PDF pages (i.e. in **Form XObjects**) never correctly worked and are now ignored. Use the items of :meth:`Document.getPageXObjectList` to determine the bboxes of embedded PDF pages.
802
+
* Images occurring inside embedded PDF pages (i.e. in **Form XObjects**) never correctly worked and are now ignored [#f5]_. Use the items of :meth:`Document.getPageXObjectList` to determine the bboxes of embedded PDF pages.
803
803
804
-
:arg list,str item: an item of the list :meth:`Page.getImageList` with *full=True* specified, or the **name** entry of such an item, which is item[-3] (or item[7] respectively). *Changed in v1.17.0:* only images are considered where item[1] == 0. This are images **directly** referenced by the page.
804
+
:arg list,str item: an item of the list :meth:`Page.getImageList` with *full=True* specified, or the **name** entry of such an item, which is item[-3] (or item[7] respectively). *Changed in v1.17.0:* only images are considered where item[1] == 0 [#f5]_. This are images **directly** referenced by the page.
805
805
806
806
:rtype::ref:`Rect`
807
807
:returns: the boundary box of the image.
808
808
*(Changed in version 1.16.7)* If the page in fact does not display this image, an infinite rectangle is returned now. In previous versions, an exception was raised.
809
-
*(Changed in version 1.17.0)* Only images referenced directly by the page are considered. This means that images occurring in embedded PDF pages are ignored and an infinite rectangle is returned.
809
+
*(Changed in version 1.17.0)* Only images referenced directly by the page are considered. This means that images occurring in embedded PDF pages are ignored and an exception is raised.
810
810
811
811
.. note::
812
812
@@ -1192,3 +1192,5 @@ The page number "pno"` is a 0-based integer *-inf < pno < pageCount*.
1192
1192
.. [#f3] Not all PDF readers display these fonts at all. Some others do, but use a wrong character spacing, etc.
1193
1193
1194
1194
.. [#f4] You are generally free to choose any of the :ref:`mupdficons` you consider adequate.
1195
+
1196
+
.. [#f5] This restriction will be removed with the next MuPDF version again: all inserted images shown on the page will be reported correctly, whether the page itself invokes them or some of its Form XObjects.
Copy file name to clipboardExpand all lines: docs/quad.rst
+10-7Lines changed: 10 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ Quads can **be obtained** as results of text search methods (:meth:`Page.searchF
14
14
15
15
* Attribute :attr:`Quad.rect` obtains the envelopping rectangle. Vice versa, rectangles now have attributes :attr:`Rect.quad`, resp. :attr:`IRect.quad` to obtain their respective tetragon versions.
@@ -56,17 +57,19 @@ Quads can **be obtained** as results of text search methods (:meth:`Page.searchF
56
57
57
58
:arg matrix_like matrix: the matrix.
58
59
59
-
.. method:: morph(point, matrix)
60
+
.. method:: morph(pivot, matrix)
60
61
61
62
*(New in version 1.17.0)* "Morph" the quad with a matrix-like using a point-like as pivotal point.
62
63
63
-
:arg point_like point: the point.
64
+
:arg point_like pivot: the point.
64
65
:arg matrix_like matrix: the matrix.
65
-
:returns: a new quad. The effect is achieved by using the following code snippet::
66
+
:returns: a new quad. The effect is achieved by using the following code::
66
67
67
-
>>> T = fitz.Matrix(1, 1).preTranslate(point.x, point.y)
68
+
>>> T = fitz.Matrix(1, 1).preTranslate(pivot.x, pivot.y)
68
69
>>> result = self * ~T * matrix * T
69
70
71
+
So the quad is translated such, that pivot becomes the origin (0, 0), then the matrix is applied to it, and finally a reverse translation is done.
72
+
70
73
Typical uses include rotating the quad around a desired point.
71
74
72
75
.. attribute:: rect
@@ -105,19 +108,19 @@ Quads can **be obtained** as results of text search methods (:meth:`Page.searchF
105
108
106
109
*(New in version 1.16.1)*
107
110
108
-
True if all lines are contained in the quad which connect two points of the quad.
111
+
True if every line connecting two points of the quad is inside the quad. We in addition also make sure here, that the quad is not "degenerate", i.e. not all corners are on the same line (which would still qualify as convexity in the mathematical sense).
109
112
110
113
:type: bool
111
114
112
115
.. attribute:: isEmpty
113
116
114
-
True if enclosed area is zero, which means that all four points are on the same line. If this is false, the quad may still be degenerate or not look like a rectangle at all (triangles, parallelograms, trapezoids, ...).
117
+
True if enclosed area is zero, which means that at least three of the four corners are on the same line. If this is false, the quad may still be degenerate or not look like a tetragon at all (triangles, parallelograms, trapezoids, ...).
115
118
116
119
:type: bool
117
120
118
121
.. attribute:: isRectangular
119
122
120
-
True if all angles are 90 degrees. This also implies that the area is **not empty** and **convex**.
123
+
True if all corner angles are 90 degrees. This implies that the quad is **convex and not empty**.
Copy file name to clipboardExpand all lines: docs/textwriter.rst
+31-21Lines changed: 31 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,24 @@
4
4
TextWriter
5
5
================
6
6
7
-
*(New in v1.16.18)* This class represents a MuPDF *text* object. It can be thought of as a store of text spans -- each span having its own position, font and font size. It is an elegant alternative for writing text to PDF pages, when compared with methods :meth:`Page.insertText` and friends:
7
+
*(New in v1.16.18)* This class represents a MuPDF *text* object. It can be thought of as a collection of text spans. Each span has its own starting position and its font and font size. It is an elegant alternative for writing text to PDF pages, when compared with methods :meth:`Page.insertText` and friends:
8
8
9
-
* **Improved text positioning:** The position of the last inserted character is returned, as well as the combined rectangle of text stored so far.
10
-
* **Automatic fallback fonts:** If a character is not represented by the chosen font, alternative fonts are automatically checked. This significantly reduces the risk of seeing unprintable symbols in the output, so-called "TOFUs". PyMuPDF now also comes with a **"universal"** font, which supports **all Latin** characters (incuding Cyrillic and Greek), and **all CJK** characters (Chinese, Japanese, Korean).
11
-
* **Reusability:** A TextWriter exists independent from any page. The same text can be written multiple times, to the same or other pages, same or different PDFs, choosing different colors or transparency.
12
-
* **Transparency support:** Parameter *opacity* is supported. This offers a handy way to write watermark-style text.
9
+
* **Improved text positioning:** Choose any point where insertion of a text span should start. The position of the last inserted character is returned, as well as the combined rectangle of all spans stored so far.
10
+
* **Free font choice:** Each text span has its own font and fontsize. This lets you easily switch between normal, bold and italic versions of either the same or a different font when composing a larger text.
11
+
* **Automatic fallback fonts:** If a character is not represented by the chosen font, alternative fonts are automatically checked. This significantly reduces the risk of seeing unprintable symbols in the output, so-called "TOFUs". PyMuPDF now also comes with the **universal font "Droid Sans Fallback Regular"**, which supports **all Latin** characters (incuding Cyrillic and Greek), and **all CJK** characters (Chinese, Japanese, Korean).
12
+
* **Transparency support:** Parameter *opacity* is supported. This offers a handy way to create watermark-style text.
13
13
* **Justified text:** Supported for any font -- not just simple fonts as in :meth:`Page.insertText`.
14
+
* **Reusability:** A TextWriter exists independent from any page. The same text can be written multiple times, either to the same or to other pages, in the same or in different PDFs, choosing different colors or transparency.
14
15
15
16
Using this object entails three steps:
16
17
17
-
1. When **created**, a TextWriter object requires a fixed **page rectangle** in relation to which it calculates text positions. Pages with different dimensions cannot use this TextWriter object.
18
-
2. Store text in the TextWriter using method either :meth:`TextWriter.append` or :meth:`TextWriter.fillTextbox`.
19
-
3. Output the stored text on any PDF page with the same rectangle. This is the only point, where pages are referenced.
18
+
1. When **created**, a TextWriter object requires a fixed **page rectangle** in relation to which it calculates text positions. Text can be written to a page if and only if the page's size equals that of the TextWriter.
19
+
2. Store text in the TextWriter using methods :meth:`TextWriter.append` or :meth:`TextWriter.fillTextbox` any number of times.
20
+
3. Output the stored text on some PDF page (having the same rectangle).
20
21
21
-
TextWriters do not support text rotation. But the new method :meth:`Page.writeText` is able to combine one or more TextWriters and jointly write them to **any rectangle** and with **any rotation angle** -- much like :meth:`Page.showPDFpage`.
22
+
Starting with version 1.17.0, TextWriters **do support** text rotation via the *morph* parameter of :meth:`TextWriter.writeText`.
23
+
24
+
There also exists :meth:`Page.writeText` which is able to combine one or more TextWriters and jointly write them to a given rectangle and with a given any rotation angle -- much like :meth:`Page.showPDFpage`.
22
25
23
26
**Class API**
24
27
@@ -41,12 +44,11 @@ TextWriters do not support text rotation. But the new method :meth:`Page.writeTe
41
44
:arg float fontsize: the fontsize, a positive number, default 11.
42
45
:arg str language: the language to use, e.g. "en" for English. Meaningful values should be compliant with the ISO 639 standards 1, 2, 3 or 5. Reserved for future use: currently has no effect as far as we know.
43
46
44
-
:returns::attr:`textRect` and :attr:`lastPoint` after this text has been added.
Fill a given rectangle with text. This is a convenience method to use instead of :meth:`append` (which is internally invoked).
51
+
Fill a given rectangle with text. This is a convenience method to use instead of :meth:`append`.
50
52
51
53
:arg rect_like rect: the area to fill. No part of the text will appear outside of this.
52
54
:arg str,sequ text: the text. Can be specified as a (UTF-8) string or a list / tuple of strings. A string will first be converted to a list using *splitlines()*. Every list item will begin on a new line (forced line breaks).
@@ -55,23 +57,27 @@ TextWriters do not support text rotation. But the new method :meth:`Page.writeTe
55
57
:arg int align: text alignment. Use one of TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_JUSTIFY.
56
58
:arg bool warn: print a warning if the area is too small, or raise an exception.
.. note:: Use these methods as often as is required -- there is no technical limit, except memory constraints of your system. You can also mix appends and text boxes and have multiple of both. Text positioning is controlled by the insertion point. There is no need to adhere to any reading order.
:arg float opacity: overwrite the value of the TextWriter for this output.
64
-
:arg sequ color: overwrite the value of the TextWriter for this output.
68
+
:arg float opacity: override the value of the TextWriter for this output.
69
+
:arg sequ color: override the value of the TextWriter for this output.
70
+
:arg sequ morph: modify the text appearance by applying a matrix to it. If provided, this must be a sequence *(pivot, matrix)* with a point-like *pivot* and a matrix-like *matrix*. A typical example is rotating the text around *pivot*.
65
71
:arg bool overlay: put in foreground (default) or background.
66
72
67
73
68
74
.. attribute:: textRect
69
75
70
-
The area currently occupied. This value changes when more text is added.
76
+
The :ref:`Rect` currently occupied. This value changes when more text is added.
71
77
72
78
.. attribute:: lastPoint
73
79
74
-
The "cursor position" after the last written character.
80
+
The "cursor position" -- a :ref:`Point` -- after the last written character (its bottom-right).
75
81
76
82
.. attribute:: opacity
77
83
@@ -83,11 +89,15 @@ TextWriters do not support text rotation. But the new method :meth:`Page.writeTe
83
89
84
90
.. attribute:: rect
85
91
86
-
The rectangle for which this TextWriter was created. Must not be modified.
92
+
The page rectangle for which this TextWriter was created. Must not be modified.
93
+
94
+
95
+
To see some demo scripts dealing with TextWriter, have a look at `this <https://github.com/pymupdf/PyMuPDF-Utilities/tree/master/textwriter>`_ rpository.
96
+
87
97
88
98
.. note::
89
99
90
100
1. Opacity and color apply to **all the text** in this object.
91
-
2. If you need different colors / transpareny, you must create a separate TextWriter. Whenever you determine the color should change, simply append the text to the respective TextWriter using the previously returned :attr:`lastPoint` as position for the new text.
92
-
3. Appending items can occur in arbitrary order: only the position parameter controls where text appears.
101
+
2. If you need different colors / transpareny, you must create a separate TextWriter. Whenever you determine the color should change, simply append the text to the respective TextWriter using the previously returned :attr:`lastPoint` as position for the new text span.
102
+
3. Appending items or text boxes can occur in arbitrary order: only the position parameter controls where text appears.
93
103
4. Font and fontsize can freely vary within the same TextWriter. This can be used to let text with different properties appear on the same displayed line: just specify *pos* accordingly, and e.g. set it to :attr:`lastPoint` of the previously added item.
0 commit comments