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
Summary: PyMuPDF is a Python binding for the PDF rendering library MuPDF
11
11
Description:
12
-
Release date: March 29, 2020
12
+
Release date: March 31, 2020
13
13
14
14
Authors
15
15
=======
@@ -20,7 +20,7 @@ Description:
20
20
Introduction
21
21
============
22
22
23
-
This is **version 1.16.16 of PyMuPDF**, a Python binding for `MuPDF <http://mupdf.com/>`_ - "a lightweight PDF and XPS viewer".
23
+
This is **version 1.16.18 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,7 +14,7 @@ On **[PyPI](https://pypi.org/project/PyMuPDF)** since August 2016: [**, a Python binding with support for [MuPDF 1.16.*](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
17
+
This is **version 1.16.17 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.16.*](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.
Copy file name to clipboardExpand all lines: docs/changes.rst
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,12 @@
1
1
Change Logs
2
2
===============
3
3
4
+
Changes in Version 1.16.17
5
+
---------------------------
6
+
7
+
* **Fixed** issue `#479 <https://github.com/pymupdf/PyMuPDF/issues/479>`_. PyMuPDF should now more correctly report image resolutions. This applies to both, images (either from images files or extracted from PDF documents) and pixmaps created from images.
8
+
* **Added** :meth:`Pixmap.setResolution` which sets the image resolution in x and y directions.
Copy file name to clipboardExpand all lines: docs/document.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,6 +170,8 @@ For addional details on **embedded files** refer to Appendix 3.
170
170
:rtype::ref:`Page`
171
171
172
172
:returns: a new copy of the same page. All pending updates (e.g. to annotations or widgets) will be finalized and a fresh copy of the page will be loaded.
173
+
.. note:: In a typical use case, a page :ref:`Pixmap` should be taken after annotations / widgets have been added or changed. To force all those changes being reflected in the page structure, this method re-instates a fresh copy while keeping the object hierarchy "document -> page -> annotation(s)" intact.
Copy file name to clipboardExpand all lines: docs/functions.rst
+7-10Lines changed: 7 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -547,11 +547,11 @@ Yet others are handy, general-purpose utilities.
547
547
:rtype: int
548
548
:returns::data:`xref` number of the **/Outlines** root object.
549
549
550
-
.. method:: Document.extractImage(xref=0)
550
+
.. method:: Document.extractImage(xref)
551
551
552
552
PDF Only: Extract data and meta information of an image stored in the document. The output can directly be used to be stored as an image file, as input for PIL, :ref:`Pixmap` creation, etc. This method avoids using pixmaps wherever possible to present the image in its original format (e.g. as JPEG).
553
553
554
-
:arg int xref::data:`xref` of an image object. Must be in *range(1, doc._getXrefLength())*, else an exception is raised. If the object is no image or other errors occur, an empty dictionary is returned and no exception occurs.
554
+
:arg int xref::data:`xref` of an image object. If this is not in *range(1, doc.xrefLength())*, or the object is no image or other errors occur, *None* is returned and no exception is raised.
555
555
556
556
:rtype: dict
557
557
:returns: a dictionary with the following keys
@@ -560,15 +560,12 @@ Yet others are handy, general-purpose utilities.
560
560
* *smask* (*int*) :data:`xref` number of a stencil (/SMask) image or zero
561
561
* *width* (*int*) image width
562
562
* *height* (*int*) image height
563
-
* *colorspace* (*int*) the image's *pixmap.n* number (indicative only: depends on whether internal pixmaps had to be used). Zero for JPX images.
563
+
* *colorspace* (*int*) the image's *colorspace.n* number.
564
564
* *cs-name* (*str*) the image's *colorspace.name*.
565
-
* *xres* (*int*) resolution in x direction. Zero for JPX images.
566
-
* *yres* (*int*) resolution in y direction. Zero for JPX images.
565
+
* *xres* (*int*) resolution in x direction. Please also see :data:`resolution`.
566
+
* *yres* (*int*) resolution in y direction. Please also see :data:`resolution`.
567
567
* *image* (*bytes*) image data, usable as image file content
@@ -579,7 +576,7 @@ Yet others are handy, general-purpose utilities.
579
576
102
580
577
>>> imgout.close()
581
578
582
-
.. note:: There is a functional overlap with *pix = fitz.Pixmap(doc, xref)*, followed by a *pix.getPNGData()*. Main differences are that extractImage **(1)** does not only deliver PNG image formats, **(2)** is **very** much faster with non-PNG images, **(3)** usually results in much less disk storage for extracted images, **(4)** generates an empty *dict* for non-image xrefs (generates no exception). Look at the following example images within the same PDF.
579
+
.. note:: There is a functional overlap with *pix = fitz.Pixmap(doc, xref)*, followed by a *pix.getPNGData()*. Main differences are that extractImage, **(1)** does not only deliver PNG image formats, **(2)** is **very** much faster with non-PNG images, **(3)** usually results in much less disk storage for extracted images, **(4)** returns *None* in error cases (generates no exception). Look at the following example images within the same PDF.
583
580
584
581
* xref 1268 is a PNG -- Comparable execution time and identical output::
585
582
@@ -593,7 +590,7 @@ Yet others are handy, general-purpose utilities.
593
590
In [26]: len(img["image"])
594
591
Out[26]: 21462
595
592
596
-
* xref 1186 is a JPEG -- :meth:`Document.extractImage` is **thousands of times faster** and produces a **much smaller** output (2.48 MB vs. 0.35 MB)::
593
+
* xref 1186 is a JPEG -- :meth:`Document.extractImage` is **many times faster** and produces a **much smaller** output (2.48 MB vs. 0.35 MB)::
597
594
598
595
In [27]: %timeit pix = fitz.Pixmap(doc, 1186);pix.getPNGData()
599
596
341 ms ± 2.86 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Copy file name to clipboardExpand all lines: docs/glossary.rst
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,3 +113,6 @@ Glossary
113
113
114
114
Abbreviation for cross-reference number: this is an integer unique identification for objects in a PDF. There exists a cross-reference table (which may physically consist of several separate segments) in each PDF, which stores the relative position of each object for quick lookup. The cross-reference table is one entry longer than the number of existing object: item zero is reserved and must not be used in any way. Many PyMuPDF classes have an *xref* attribute (which is zero for non-PDFs), and one can find out the total number of objects in a PDF via :meth:`Document.xrefLength` *- 1*.
115
115
116
+
.. data:: resolution
117
+
118
+
Images and :ref:`Pixmap` objects may contain resolution information provided as "dots per inch", dpi, in each direction (horizontal and vertical). When MuPDF reads an image form a file or from a PDF object, it will parse this information and put it in :attr:`Pixmap.xres`, :attr:`Pixmap.yres`, respectively. When it finds not meaningful information in the input (like non-positive values or values exceeding 4800), it will use "sane" defaults instead. The usual default value is 96, but it may also be 72 in some cases (e.g. 72 for JPX images).
:meth:`Pixmap.tintWith` tint a pixmap with a color
@@ -224,6 +225,16 @@ Have a look at the :ref:`FAQ` section to see some pixmap usage "at work".
224
225
1. This method is equivalent to :meth:`Pixmap.setPixel` executed for each pixel in the rectangle, but is obviously **very much faster** if many pixels are involved.
225
226
2. This method can be used similar to :meth:`Pixmap.clearWith` to initialize a pixmap with a certain color like this: *pix.setRect(pix.irect, (255, 255, 0))* (RGB example, colors the complete pixmap with yellow).
226
227
228
+
.. method:: setResolution(xres, yres)
229
+
230
+
*(New in v1.16.17)* Set the resolution (dpi) in x and y direction.
231
+
232
+
:arg int xres: resolution in x direction.
233
+
:arg int yres: resolution in y direction.
234
+
235
+
.. note:: This is just documentary information. In MuPDF, this will not have other implications and will not be written to images created from the pixmap.
236
+
237
+
227
238
.. method:: setAlpha([alphavalues])
228
239
229
240
Change the alpha values. The pixmap must have an alpha channel.
@@ -362,13 +373,13 @@ Have a look at the :ref:`FAQ` section to see some pixmap usage "at work".
362
373
363
374
.. attribute:: xres
364
375
365
-
Horizontal resolution in dpi (dots per inch).
376
+
Horizontal resolution in dpi (dots per inch). Please also see :data:`resolution`.
366
377
367
378
:type: int
368
379
369
380
.. attribute:: yres
370
381
371
-
Vertical resolution in dpi.
382
+
Vertical resolution in dpi. Please also see :data:`resolution`.
:meth:`Tools.store_shrink` shrink the storables cache [#f1]_
13
14
:meth:`Tools.mupdf_warnings` return the accumulated MuPDF warnings
14
15
:meth:`Tools.mupdf_display_errors` return the accumulated MuPDF warnings
@@ -36,6 +37,45 @@ This class is a collection of utility methods and attributes, mainly around memo
36
37
:rtype: int
37
38
:returns: a unique positive integer.
38
39
40
+
.. method:: image_profile(stream)
41
+
42
+
*(New in v1.16.17)* Show important properties of an image provided as a memory area. Its main purpose is to avoid using other Python packages just to determine basic properties.
43
+
44
+
:arg bytes,bytearray stream: the image data.
45
+
:rtype: dict
46
+
:returns: a dictionary with the keys "width", "height", "xres", "yres", "colorspace" (the *colorspace.n* value, number of colorants), "cs-name" (the *colorspace.name* value), "bpc", "ext" (image type as file extension). The values for these keys are the same as returned by :meth:`Document.extractImage`. Please also have a look at :data:`resolution`.
47
+
48
+
.. note::
49
+
50
+
* For some "exotic" images (FAX encodings, RAW formats and the like), this method will not work and return *None*. You can however still work with such images in PyMuPDF, e.g. by using :meth:`Document.extractImage` or create pixmaps via ``Pixmap(doc, xref)``. These methods will automatically convert exotic images to the PNG format before returning results.
51
+
52
+
* Some examples::
53
+
54
+
In [1]: import fitz
55
+
In [2]: stream = open(<image.file>, "rb").read()
56
+
In [3]: fitz.TOOLS.image_profile(stream)
57
+
Out[3]:
58
+
{'width': 439,
59
+
'height': 501,
60
+
'xres': 96,
61
+
'yres': 96,
62
+
'colorspace': 3,
63
+
'bpc': 8,
64
+
'ext': 'jpeg',
65
+
'cs-name': 'DeviceRGB'}
66
+
In [4]: doc=fitz.open(<input.pdf>)
67
+
In [5]: stream = doc.xrefStreamRaw(5) # no decompression!
68
+
In [6]: fitz.TOOLS.image_profile(stream)
69
+
Out[6]:
70
+
{'width': 816,
71
+
'height': 1056,
72
+
'xres': 96,
73
+
'yres': 96,
74
+
'colorspace': 1,
75
+
'bpc': 8,
76
+
'ext': 'jpeg',
77
+
'cs-name': 'DeviceGray'}
78
+
39
79
.. method:: store_shrink(percent)
40
80
41
81
Reduce the storables cache by a percentage of its current size.
This documentation covers PyMuPDF v1.16.16 features as of **2020-03-29 09:44:30**.
4
+
This documentation covers PyMuPDF v1.16.17 features as of **2020-03-31 08:53:33**.
5
5
6
6
.. note:: The major and minor versions of **PyMuPDF** and **MuPDF** will always be the same. Only the third qualifier (patch level) may be different from that of MuPDF.
0 commit comments