Skip to content

Commit 715a017

Browse files
committed
upgrade to v1.16.17
1 parent 05b3baf commit 715a017

20 files changed

+764
-198
lines changed

PKG-INFO

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.1
22
Name: PyMuPDF
3-
Version: 1.16.16
3+
Version: 1.16.17
44
Author: Ruikai Liu
55
Author-email: [email protected]
66
Maintainer: Jorj X. McKie
@@ -9,7 +9,7 @@ Home-page: https://github.com/pymupdf/PyMuPDF
99
Download-url: https://github.com/pymupdf/PyMuPDF
1010
Summary: PyMuPDF is a Python binding for the PDF rendering library MuPDF
1111
Description:
12-
Release date: March 29, 2020
12+
Release date: March 31, 2020
1313

1414
Authors
1515
=======
@@ -20,7 +20,7 @@ Description:
2020
Introduction
2121
============
2222

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".
2424

2525
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.
2626

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# PyMuPDF 1.16.16
1+
# PyMuPDF 1.16.17
22

33
![logo](https://github.com/pymupdf/PyMuPDF/blob/master/demo/pymupdf.jpg)
44

5-
Release date: March 29, 2020
5+
Release date: March 31, 2020
66

77
**Travis-CI:** [![Build Status](https://travis-ci.org/JorjMcKie/py-mupdf.svg?branch=master)](https://travis-ci.org/JorjMcKie/py-mupdf)
88

@@ -14,7 +14,7 @@ On **[PyPI](https://pypi.org/project/PyMuPDF)** since August 2016: [![](https://
1414

1515
# Introduction
1616

17-
This is **version 1.16.16 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".
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".
1818

1919
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.
2020

docs/changes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Change Logs
22
===============
33

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.
9+
410
Changes in Version 1.16.16
511
---------------------------
612

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# built documents.
4747
#
4848
# The full version, including alpha/beta/rc tags.
49-
release = "1.16.16"
49+
release = "1.16.17"
5050

5151
# The short X.Y version
5252
version = release

docs/document.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ For addional details on **embedded files** refer to Appendix 3.
170170
:rtype: :ref:`Page`
171171

172172
: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.
174+
173175

174176
.. method:: pages(start=None, [stop=None, [step=None]])
175177

docs/functions.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,11 @@ Yet others are handy, general-purpose utilities.
547547
:rtype: int
548548
:returns: :data:`xref` number of the **/Outlines** root object.
549549

550-
.. method:: Document.extractImage(xref=0)
550+
.. method:: Document.extractImage(xref)
551551

552552
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).
553553

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.
555555

556556
:rtype: dict
557557
:returns: a dictionary with the following keys
@@ -560,15 +560,12 @@ Yet others are handy, general-purpose utilities.
560560
* *smask* (*int*) :data:`xref` number of a stencil (/SMask) image or zero
561561
* *width* (*int*) image width
562562
* *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.
564564
* *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`.
567567
* *image* (*bytes*) image data, usable as image file content
568568

569-
>>> d = doc.extractImage(25)
570-
>>> d
571-
{}
572569
>>> d = doc.extractImage(1373)
573570
>>> d
574571
{'ext': 'png', 'smask': 2934, 'width': 5, 'height': 629, 'colorspace': 3, 'xres': 96,
@@ -579,7 +576,7 @@ Yet others are handy, general-purpose utilities.
579576
102
580577
>>> imgout.close()
581578

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.
583580

584581
* xref 1268 is a PNG -- Comparable execution time and identical output::
585582

@@ -593,7 +590,7 @@ Yet others are handy, general-purpose utilities.
593590
In [26]: len(img["image"])
594591
Out[26]: 21462
595592

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)::
597594

598595
In [27]: %timeit pix = fitz.Pixmap(doc, 1186);pix.getPNGData()
599596
341 ms ± 2.86 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

docs/glossary.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,6 @@ Glossary
113113

114114
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*.
115115

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).

docs/pixmap.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Have a look at the :ref:`FAQ` section to see some pixmap usage "at work".
3232
:meth:`Pixmap.pixel` return the value of a pixel
3333
:meth:`Pixmap.setPixel` set the color of a pixel
3434
:meth:`Pixmap.setRect` set the color of a rectangle
35+
:meth:`Pixmap.setResolution` set the image resolution
3536
:meth:`Pixmap.setAlpha` set alpha values
3637
:meth:`Pixmap.shrink` reduce size keeping proportions
3738
: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".
224225
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.
225226
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).
226227

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+
227238
.. method:: setAlpha([alphavalues])
228239

229240
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".
362373

363374
.. attribute:: xres
364375

365-
Horizontal resolution in dpi (dots per inch).
376+
Horizontal resolution in dpi (dots per inch). Please also see :data:`resolution`.
366377

367378
:type: int
368379

369380
.. attribute:: yres
370381

371-
Vertical resolution in dpi.
382+
Vertical resolution in dpi. Please also see :data:`resolution`.
372383

373384
:type: int
374385

docs/tools.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This class is a collection of utility methods and attributes, mainly around memo
99
**Method / Attribute** **Description**
1010
================================== =================================================
1111
:meth:`Tools.gen_id` generate a unique identifyer
12+
:meth:`Tools.image_profile` report basic image properties
1213
:meth:`Tools.store_shrink` shrink the storables cache [#f1]_
1314
:meth:`Tools.mupdf_warnings` return the accumulated MuPDF warnings
1415
: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
3637
:rtype: int
3738
:returns: a unique positive integer.
3839

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+
3979
.. method:: store_shrink(percent)
4080

4181
Reduce the storables cache by a percentage of its current size.

docs/version.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Covered Version
22
--------------------
33

4-
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**.
55

66
.. 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

Comments
 (0)