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
This is **version 1.17.1 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
23
+
This is **version 1.17.2 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
24
24
25
25
MuPDF can access files in PDF, XPS, OpenXPS, epub, comic and fiction book formats, and it is known for both, its top performance and high rendering quality.
@@ -14,15 +14,15 @@ On **[PyPI](https://pypi.org/project/PyMuPDF)** since August 2016: [ - "a lightweight PDF, XPS, and E-book viewer".
17
+
This is **version 1.17.2 of PyMuPDF**, a Python binding with support for [MuPDF 1.17.*](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
18
18
19
19
MuPDF can access files in PDF, XPS, OpenXPS, CBZ, EPUB and FB2 (e-books) formats, and it is known for its top performance and high rendering quality.
20
20
21
-
With PyMuPDF you can access files with extensions like ".pdf", ".xps", ".oxps", ".cbz", ".fb2" or ".epub". About 10 popular image formats are also supported via the document interface.
21
+
With PyMuPDF you can access files with extensions like ".pdf", ".xps", ".oxps", ".cbz", ".fb2" or ".epub". In addition, about 10 popular image formats can also be opened and handled like documents.
22
22
23
23
24
24
# Usage and Documentation
25
-
For all supported document types (i.e. including images) you can
25
+
For all supported document types (i.e. **_including images_**) you can
26
26
* decrypt the document
27
27
* access meta information, links and bookmarks
28
28
* render pages in raster formats (PNG and some others), or the vector format SVG
@@ -32,14 +32,14 @@ For all supported document types (i.e. including images) you can
32
32
33
33
> To some degree, PyMuPDF can therefore be used as an [image converter](https://github.com/pymupdf/PyMuPDF/wiki/How-to-Convert-Images): it can read a range of input formats and can produce **Portable Network Graphics (PNG)**, **Portable Anymaps** (**PNM**, etc.), **Portable Arbitrary Maps (PAM)**, **Adobe Postscript** and **Adobe Photoshop** documents, making the use of other graphics packages obselete in these cases. But interfacing with e.g. PIL/Pillow for image input and output is easy as well.
34
34
35
-
**PDF files** can be created, joined or split up. Pages can be inserted, deleted, re-arranged or modified in many ways (including annotations and form fields).
35
+
**PDF documents** can be created, joined or split up. Pages can be inserted, deleted, re-arranged or modified in many ways (including annotations and form fields).
36
36
37
37
* Images and fonts can be extracted or inserted.
38
38
* Embedded files are fully supported.
39
39
* PDFs can be reformatted to support double-sided printing, posterizing, applying logos or watermarks
40
40
* Password protection is fully supported: decryption, encryption, encryption method selection, permmission level and user / owner password setting.
41
41
* Low-level PDF structures can be accessed and modified.
42
-
* PyMuPDF can also be used as a **module in the command line** using ``"python -m fitz ..."``. This is a versatile utility, which we will further develop over time. It currently supports PDF document
42
+
* PyMuPDF can also be used as a **module in the command line** using ``"python -m fitz ..."``. This is a versatile utility, which we will further develop going forward. It currently supports PDF document
Copy file name to clipboardExpand all lines: docs/annot.rst
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,7 +141,7 @@ There is a parent-child relationship between an annotation and its page. If the
141
141
142
142
:arg rect_like rect: the new rectangle of the annotation (finite and not empty). E.g. using a value of *annot.rect + (5, 5, 5, 5)* will shift the annot position 5 pixels to the right and downwards.
143
143
144
-
.. note:: You need not invoke :meth:`Annot.update` for activation of the effect.
144
+
.. note:: You **need not** invoke :meth:`Annot.update` for activation of the effect.
145
145
146
146
147
147
.. method:: setRotation(angle)
@@ -196,9 +196,10 @@ There is a parent-child relationship between an annotation and its page. If the
Synchronize the appearance of an annotation with its properties after any changes.
204
205
@@ -223,6 +224,7 @@ There is a parent-child relationship between an annotation and its page. If the
223
224
* 'FreeText' annotations: If you set (or leave) this to *None*, then **no rectangle at all** will be drawn around the text, and the border color will be ignored. This will leave anything "under" the text visible.
224
225
* 'Line', 'Polyline', 'Polygon' annotations: use it to give applicable line end symbols a fill color other than that of the annotation *(changed in v1.16.16)*.
225
226
227
+
:arg bool cross_out: *(new in v1.17.2)* add two diagonal lines to the annotation rectangle. 'Redact' annotations only. If not desired, *False* must be specified even if the annotation was created with *False*.
226
228
:arg int rotate: new rotation value. Default (-1) means no change. Supports 'FreeText' and several other annotation types (see `Annot.setRotation`), [#f1]_. Only choose 0, 90, 180, or 270 degrees for 'FreeText'. Otherwise any integer is acceptable.
@@ -151,13 +153,23 @@ For addional details on **embedded files** refer to Appendix 3.
151
153
* bit 2 set => **owner** password authenticated
152
154
153
155
156
+
.. method:: chapterPageCount(chapter)
157
+
158
+
*(New in v.1.17.0)* Return the number of pages of a chapter.
159
+
160
+
:arg int chapter: the 0-based chapter number.
161
+
162
+
:rtype: int
163
+
:returns: number of pages in chapter. Relevant only for document types whith chapter support (EPUB currently).
164
+
165
+
154
166
.. method:: nextLocation(page_id)
155
167
156
168
*(New in v.1.17.0)* Return the locator of the following page.
157
169
158
170
:arg tuple page_id: the current page id. This must be a tuple *(chapter, pno)* identifying an existing page.
159
171
160
-
:returns: The tuple of the following page, i.e. either *(chapter, pno + 1)* or *(chapter + 1, 0)*, **or** the empty tuple *()* if the argument was the last page.
172
+
:returns: The tuple of the following page, i.e. either *(chapter, pno + 1)* or *(chapter + 1, 0)*, **or** the empty tuple *()* if the argument was the last page. Relevant only for document types whith chapter support (EPUB currently).
161
173
162
174
163
175
.. method:: previousLocation(page_id)
@@ -166,7 +178,7 @@ For addional details on **embedded files** refer to Appendix 3.
166
178
167
179
:arg tuple page_id: the current page id. This must be a tuple *(chapter, pno)* identifying an existing page.
168
180
169
-
:returns: The tuple of the preceeding page, i.e. either *(chapter, pno - 1)* or the last page of the receeding chapter, **or** the empty tuple *()* if the argument was the first page.
181
+
:returns: The tuple of the preceeding page, i.e. either *(chapter, pno - 1)* or the last page of the receeding chapter, **or** the empty tuple *()* if the argument was the first page. Relevant only for document types whith chapter support (EPUB currently).
170
182
171
183
172
184
.. method:: loadPage(page_id=0)
@@ -179,7 +191,7 @@ For addional details on **embedded files** refer to Appendix 3.
179
191
180
192
Either a 0-based page number, or a tuple *(chapter, pno)*. For an integer, any *-inf < page_id < pageCount* is acceptable. While page_id is negative, :attr:`pageCount` will be added to it. For example: to load the last page, you can use *doc.loadPage(-1)*. After this you have page.number = doc.pageCount - 1.
181
193
182
-
For a tuple, *chapter* must be in range :attr:`Document.chapterCount`, and *pno* must be in range :meth:`Document.chapterPageCount` of that chapter. Both values are 0-based. With this notation, :attr:`Page.number` will equal the given tuple.
194
+
For a tuple, *chapter* must be in range :attr:`Document.chapterCount`, and *pno* must be in range :meth:`Document.chapterPageCount` of that chapter. Both values are 0-based. With this notation, :attr:`Page.number` will equal the given tuple. Relevant only for document types whith chapter support (EPUB currently).
183
195
184
196
:rtype::ref:`Page`
185
197
@@ -684,11 +696,11 @@ For addional details on **embedded files** refer to Appendix 3.
684
696
685
697
.. method:: getSigFlags()
686
698
687
-
PDF only: Return whether the document contains signature fields.
699
+
PDF only: Return whether the document contains signature fields. This is an optional PDF property: if not present, no conclusions can be drawn, because the PDF creator may just not have bothered to use it.
688
700
689
701
:rtype: int
690
702
:returns:
691
-
* -1: not a Form PDF or no signature fields exist.
703
+
* -1: not a Form PDF / no signature fields recorded / no *SigFlags* found.
692
704
* 1: at least one signature field exists.
693
705
* 3: contains signatures that may be invalidated if the file is saved (written) in a way that alters its previous contents, as opposed to an incremental update.
694
706
@@ -932,6 +944,20 @@ For addional details on **embedded files** refer to Appendix 3.
932
944
933
945
:type: int
934
946
947
+
.. Attribute:: chapterCount
948
+
949
+
*(New in version 1.17.0)*
950
+
Contains the number of chapters in the document. Always at least 1. Relevant only for document types with chapter support (EPUB currently). Other documents will return 1.
951
+
952
+
:type: int
953
+
954
+
.. Attribute:: lastLocation
955
+
956
+
*(New in version 1.17.0)*
957
+
Contains (chapter, pno) of the document's last page. Relevant only for document types with chapter support (EPUB currently). Other documents will return *(0, len(doc) - 1)* and *(0, -1)* if it has no pages.
958
+
959
+
:type: int
960
+
935
961
.. Attribute:: FormFonts
936
962
937
963
A list of form field font names defined in the */AcroForm* object. *None* if not a PDF.
Copy file name to clipboardExpand all lines: docs/functions.rst
+19-10Lines changed: 19 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,14 +42,15 @@ Yet others are handy, general-purpose utilities.
42
42
:meth:`getPDFnow` return the current timestamp in PDF format
43
43
:meth:`getPDFstr` return PDF-compatible string
44
44
:meth:`getTextlength` return string length for a given font & fontsize
45
-
:meth:`Page._cleanContents` PDF only: clean the page's :data:`contents` objects
45
+
:meth:`Page.cleanContents` PDF only: clean the page's :data:`contents` objects
46
46
:meth:`Page._getContents` PDF only: return a list of content numbers
47
47
:meth:`Page._setContents` PDF only: set page's :data:`contents` to some :data:`xref`
48
48
:meth:`Page.getDisplayList` create the page's display list
49
49
:meth:`Page.getTextBlocks` extract text blocks as a Python list
50
50
:meth:`Page.getTextWords` extract text words as a Python list
51
51
:meth:`Page.run` run a page through a device
52
-
:meth:`Page._wrapContents` wrap contents with stacking commands
52
+
:meth:`Page.readContents` PDF only: get complete, concatenated /Contents source
53
+
:meth:`Page.wrapContents` wrap contents with stacking commands
53
54
:attr:`Page._isWrapped` check whether contents wrapping is present
54
55
:meth:`planishLine` matrix to map a line to the x-axis
55
56
:meth:`PaperSize` return width, height for a known paper format
@@ -167,13 +168,13 @@ Yet others are handy, general-purpose utilities.
167
168
168
169
-----
169
170
170
-
.. method:: ImageProperties(image)
171
+
.. method:: ImageProperties(stream)
171
172
172
173
*(New in version 1.14.14)*
173
-
174
+
174
175
Return a number of basic properties for an image.
175
176
176
-
:arg bytes|bytearray|BytesIO|file image: an image either in memory or an **opened** file. A memory resident image maybe any of the formats *bytes*, *bytearray* or *io.BytesIO*.
177
+
:arg bytes|bytearray|BytesIO|file stream: an image either in memory or an **opened** file. A memory resident image maybe any of the formats *bytes*, *bytearray* or *io.BytesIO*.
177
178
178
179
:returns: a dictionary with the following keys (an empty dictionary for any error):
179
180
@@ -185,7 +186,7 @@ Yet others are handy, general-purpose utilities.
185
186
colorspace (int) colorspace.n (e.g. 3 = RGB)
186
187
bpc (int) bits per component (usually 8)
187
188
format (int) image format in *range(15)*
188
-
ext (str) suggested image file extension for the format
189
+
ext (str) image file extension indicating the format
@@ -319,17 +320,17 @@ Yet others are handy, general-purpose utilities.
319
320
320
321
-----
321
322
322
-
.. method:: Page._wrapContents
323
+
.. method:: Page.wrapContents
323
324
324
325
Put string pair "q" / "Q" before, resp. after a page's */Contents* object(s) to ensure that any "geometry" changes are **local** only.
325
326
326
-
Use this method as an alternative, minimalistic version of :meth:`Page._cleanContents`. Its advantage is a small footprint in terms of processing time and impact on incremental saves.
327
+
Use this method as an alternative, minimalistic version of :meth:`Page.cleanContents`. Its advantage is a small footprint in terms of processing time and impact on incremental saves.
327
328
328
329
-----
329
330
330
331
.. attribute:: Page._isWrapped
331
332
332
-
Indicate whether :meth:`Page._wrapContents` may be required for object insertions in standard PDF geometry. Please note that this is a quick, basic check only: a value of *False* may still be a false alarm.
333
+
Indicate whether :meth:`Page.wrapContents` may be required for object insertions in standard PDF geometry. Please note that this is a quick, basic check only: a value of *False* may still be a false alarm.
333
334
334
335
-----
335
336
@@ -381,14 +382,22 @@ Yet others are handy, general-purpose utilities.
381
382
382
383
-----
383
384
384
-
.. method:: Page._cleanContents()
385
+
.. method:: Page.cleanContents()
385
386
386
387
Clean and concatenate all :data:`contents` objects associated with this page. "Cleaning" includes syntactical corrections, standardizations and "pretty printing" of the contents stream. Discrepancies between :data:`contents` and :data:`resources` objects will also be corrected. See :meth:`Page._getContents` for more details.
387
388
388
389
Changed in version 1.16.0 Annotations are no longer implicitely cleaned by this method. Use :meth:`Annot._cleanContents` separately.
389
390
390
391
.. warning:: This is a complex function which may generate large amounts of new data and render other data unused. It is **not recommended** using it together with the **incremental save** option. Also note that the resulting singleton new */Contents* object is **uncompressed**. So you should save to a **new file** using options *"deflate=True, garbage=3"*.
391
392
393
+
-----
394
+
395
+
.. method:: Page.readContents()
396
+
397
+
*New in version 1.17.0.*
398
+
Return the concatenation of all :data:`contents` objects associated with the page -- without cleaning or otherwise modifying them. Use this method whenever you need to parse this source in its entirety whithout having to bother how many separate contents objects exist.
PDF only: *(new in version 1.16.11)* Add a redaction annotation. A redaction annotation identifies content to be removed from the document. Adding such an annotation is the first of two steps. It makes visible what will be removed in the subsequent step, :meth:`Page.apply_redactions`.
222
222
@@ -230,12 +230,14 @@ In a nutshell, this is what you can do with PyMuPDF:
230
230
231
231
:arg int align: *(New in v1.16.12)* the horizontal alignment for the replacing text. See :meth:`insertTextbox` for available values. The vertical alignment is always (approximately) centered.
232
232
233
-
:arg sequence fill: *(New in v1.16.12)* the fill color of the rectangle after applying the redaction. The default is *white = (1, 1, 1)*, which is also taken if *None* is specified. *(Changed in v1.16.13)* To suppress any fill color, specify *False*. In this cases the rectangle remains transparent.
233
+
:arg sequence fill: *(New in v1.16.12)* the fill color of the rectangle **after applying** the redaction. The default is *white = (1, 1, 1)*, which is also taken if *None* is specified. *(Changed in v1.16.13)* To suppress a fill color alltogether, specify *False*. In this cases the rectangle remains transparent.
234
234
235
235
:arg sequence text_color: *(New in v1.16.12)* the color of the replacing text. Default is *black = (0, 0, 0)*.
236
236
237
+
:arg bool cross_out: *(new in v1.17.2)* add two diagonal lines to the annotation rectangle.
238
+
237
239
:rtype::ref:`Annot`
238
-
:returns: the created annotation. The appearance of a redaction annotation cannot be changed (except for its rectangle). A redaction is displayed as a crossed-out transparent rectangle with red lines.
240
+
:returns: the created annotation. *(Changed in v1.17.2)* Its standard appearance looks like a red rectangle (no fill color), optionally showing two diagonal lines. Colors, line width, dashing, opacity and blend mode can now be set and applied via :meth:`Annot.update` like with other annotations.
0 commit comments