Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions docs/annot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ There is a parent-child relationship between an annotation and its page. If the
pair: xhtml; Annot.get_text
pair: xml; Annot.get_text

.. method:: get_text(opt, clip=None, flags=None)
.. method:: get_text(option="text", clip=None, flags=None)

* New in 1.18.0

Retrieves the content of the annotation in a variety of formats -- much like the same method for :ref:`Page`.. This currently only delivers relevant data for annotation types 'FreeText' and 'Stamp'. Other types return an empty string (or equivalent objects).

:arg str opt: (positional only) the desired format - one of the following values. Please note that this method works exactly like the same-named method of :ref:`Page`.
:arg str option: the desired format - one of the following values. Please note that this method works exactly like the same-named method of :ref:`Page`.

* "text" -- :meth:`TextPage.extractTEXT`, default
* "blocks" -- :meth:`TextPage.extractBLOCKS`
Expand All @@ -138,7 +138,7 @@ There is a parent-child relationship between an annotation and its page. If the
:arg rect-like rect: the area to consider, defaults to :attr:`Annot.rect`.


.. method:: get_textpage(clip=None, flags=3)
.. method:: get_textpage(clip=None, flags=0)

Create a :ref:`TextPage` for the annotation.

Expand Down Expand Up @@ -178,11 +178,11 @@ There is a parent-child relationship between an annotation and its page. If the
:arg int start: The symbol number for the first point.
:arg int end: The symbol number for the last point.

.. method:: set_oc(xref)
.. method:: set_oc(oc=0)

Set the annotation's visibility using PDF optional content mechanisms. This visibility is controlled by the user interface of supporting PDF viewers. It is independent from other attributes like :attr:`Annot.flags`.

:arg int xref: the :data:`xref` of an optional contents group (OCG or OCMD). Any previous xref will be overwritten. If zero, a previous entry will be removed. An exception occurs if the xref is not zero and does not point to a valid PDF object.
:arg int oc: the :data:`xref` of an optional contents group (OCG or OCMD). Any previous xref will be overwritten. If zero, a previous entry will be removed. An exception occurs if the xref is not zero and does not point to a valid PDF object.

.. note:: This does **not require executing** :meth:`Annot.update` to take effect.

Expand All @@ -204,13 +204,13 @@ There is a parent-child relationship between an annotation and its page. If the
.. note:: Must refer to an existing annotation on this page. Setting this property requires no subsequent `update()`.


.. method:: set_open(value)
.. method:: set_open(is_open)

* New in v1.18.4

Set the annotation's Popup annotation to open or closed -- **or** the annotation itself, if its type is 'Text' ("sticky note").

:arg bool value: the desired open state.
:arg bool is_open: the desired open state.


.. method:: set_popup(rect)
Expand All @@ -223,11 +223,11 @@ There is a parent-child relationship between an annotation and its page. If the



.. method:: set_opacity(value)
.. method:: set_opacity(opacity)

Set the annotation's transparency. Opacity can also be set in :meth:`Annot.update`.

:arg float value: a float in range *[0, 1]*. Any value outside is assumed to be 1. E.g. a value of 0.5 sets the transparency to 50%.
:arg float opacity: a float in range *[0, 1]*. Any value outside is assumed to be 1. E.g. a value of 0.5 sets the transparency to 50%.

Three overlapping 'Circle' annotations with each opacity set to 0.5:

Expand All @@ -243,13 +243,13 @@ There is a parent-child relationship between an annotation and its page. If the
:returns: the blend mode or ``None``.


.. method:: set_blendmode(blendmode)
.. method:: set_blendmode(blend_mode)

* New in v1.16.14

Set the annotation's blend mode. See :ref:`AdobeManual`, page 324 for explanations. The blend mode can also be set in :meth:`Annot.update`.

:arg str blendmode: set the blend mode. Use :meth:`Annot.update` to reflect this in the visual appearance. For predefined values see :ref:`BlendModes`. Use `PDF_BM_Normal` to **remove** a blend mode.
:arg str blend_mode: set the blend mode. Use :meth:`Annot.update` to reflect this in the visual appearance. For predefined values see :ref:`BlendModes`. Use `PDF_BM_Normal` to **remove** a blend mode.


.. method:: set_name(name)
Expand All @@ -271,19 +271,19 @@ There is a parent-child relationship between an annotation and its page. If the
.. note:: You **need not** invoke :meth:`Annot.update` for activation of the effect.


.. method:: set_rotation(angle)
.. method:: set_rotation(rotate=0)

Set the rotation of an annotation. This rotates the annotation rectangle around its center point. Then a **new annotation rectangle** is calculated from the resulting quad.

:arg int angle: rotation angle in degrees. Arbitrary values are possible, but will be clamped to the interval `[0, 360)`.
:arg int rotate: rotation angle in degrees. Arbitrary values are possible, but will be clamped to the interval `[0, 360)`.

.. note::
* You **must invoke** :meth:`Annot.update` to activate the effect.
* For PDF_ANNOT_FREE_TEXT, only one of the values 0, 90, 180 and 270 is possible and will **rotate the text** inside the current rectangle (which remains unchanged). Other values are silently ignored and replaced by 0.
* Otherwise, only the following :ref:`AnnotationTypes` can be rotated: 'Square', 'Circle', 'Caret', 'Text', 'FileAttachment', 'Ink', 'Line', 'Polyline', 'Polygon', and 'Stamp'. For all others the method is a no-op.


.. method:: set_border(border=None, width=None, style=None, dashes=None, clouds=None)
.. method:: set_border(border=None, width=-1, style=None, dashes=None, clouds=-1)

* Changed in version 1.16.9: Allow specification without using a dictionary. The direct parameters are used if *border* is not a dictionary.

Expand Down Expand Up @@ -339,13 +339,14 @@ There is a parent-child relationship between an annotation and its page. If the
.. index::
pair: blend_mode; Annot.update
pair: fontsize; Annot.update
pair: fontname; Annot.update
pair: text_color; Annot.update
pair: border_color; Annot.update
pair: fill_color; Annot.update
pair: cross_out; Annot.update
pair: rotate; Annot.update

.. method:: update(opacity=None, blend_mode=None, fontsize=0, text_color=None, border_color=None, fill_color=None, cross_out=True, rotate=-1)
.. method:: update(blend_mode=None, opacity=None, fontsize=0, fontname=None, text_color=None, border_color=None, fill_color=None, cross_out=True, rotate=-1)

Synchronize the appearance of an annotation with its properties after relevant changes.

Expand All @@ -361,12 +362,14 @@ There is a parent-child relationship between an annotation and its page. If the

Color specifications may be made in the usual format used in PuMuPDF as sequences of floats ranging from 0.0 to 1.0 (including both). The sequence length must be 1, 3 or 4 (supporting GRAY, RGB and CMYK colorspaces respectively). For GRAY, just a float is also acceptable.

:arg float opacity: *(new in v1.16.14)* **valid for all annotation types:** change or set the annotation's transparency. Valid values are *0 <= opacity < 1*.

:arg str blend_mode: *(new in v1.16.14)* **valid for all annotation types:** change or set the annotation's blend mode. For valid values see :ref:`BlendModes`.

:arg float opacity: *(new in v1.16.14)* **valid for all annotation types:** change or set the annotation's transparency. Valid values are *0 <= opacity < 1*.

:arg float fontsize: change :data:`fontsize` of the text. 'FreeText' annotations only.

:arg str fontname: change the font of the text. 'FreeText' annotations only. Only the Base-14 font abbreviations are supported: names starting with "Co" / "co" select Courier, "Ti" / "ti" Times-Roman, "Sy" / "sy" Symbol, "Za" / "za" ZapfDingbats; any other value selects Helvetica. ``None`` (the default) keeps the current font.

:arg sequence,float text_color: change the text color. 'FreeText' annotations only. This has the same effect as ``border_color``. Note that the text color of rich-text annotations cannot be changed at all because it is set by HTML / CSS syntax and part of the text itself.

:arg sequence,float border_color: change the border color. 'FreeText' annotations only. This has the same effect as ``text_color``.
Expand All @@ -377,7 +380,7 @@ There is a parent-child relationship between an annotation and its page. If the

:arg int rotate: new rotation value. Default (-1) means no change. Supports 'FreeText' and several other annotation types (see :meth:`Annot.set_rotation`), [#f1]_. Only choose 0, 90, 180, or 270 degrees for 'FreeText'. Otherwise any integer is acceptable.

:rtype: bool
:returns: ``None``. A ``RuntimeError`` is raised if the appearance could not be updated.

This method is the only way to change the colors of a FreeText annotation. You cannot use :meth:`Annot.set_colors` for this purpose. But be aware that for rich-text annotations, the text color is never changed. The text color is set by the ``text_color`` entry of the ``info`` dictionary. This is a limitation of |MuPDF| and not a bug.

Expand All @@ -399,16 +402,16 @@ There is a parent-child relationship between an annotation and its page. If the
:returns: the content of the attached file.

.. index::
pair: buffer; Annot.update_file
pair: buffer_; Annot.update_file
pair: filename; Annot.update_file
pair: ufilename; Annot.update_file
pair: desc; Annot.update_file

.. method:: update_file(buffer=None, filename=None, ufilename=None, desc=None)
.. method:: update_file(buffer_=None, filename=None, ufilename=None, desc=None)

Updates the content of an attached file. All arguments are optional. No arguments lead to a no-op.

:arg bytes|bytearray|BytesIO buffer: the new file content. Omit to only change meta-information.
:arg bytes|bytearray|BytesIO buffer_: the new file content. Omit to only change meta-information.

*(Changed in version 1.14.13)* *io.BytesIO* is now also supported.

Expand Down
4 changes: 2 additions & 2 deletions docs/colorspace.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Represents the color space of a :ref:`Pixmap`.

.. class:: Colorspace

.. method:: __init__(self, n)
.. method:: __init__(self, type_)

Constructor

:arg int n: A number identifying the colorspace. Possible values are :data:`CS_RGB`, :data:`CS_GRAY` and :data:`CS_CMYK`.
:arg int type_: A number identifying the colorspace. Possible values are :data:`CS_RGB`, :data:`CS_GRAY` and :data:`CS_CMYK`.

.. attribute:: name

Expand Down
40 changes: 28 additions & 12 deletions docs/device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,48 @@
.. _Device:

================
Device
DeviceWrapper
================

The different format handlers (pdf, xps, etc.) interpret pages to a "device". Devices are the basis for everything that can be done with a page: rendering, text extraction and searching. The device type is determined by the selected construction method.

In |PyMuPDF| a device is represented by class `pymupdf.DeviceWrapper`, which wraps a low-level |MuPDF| device (available as its attribute `this`). Most users never create one directly: :meth:`DocumentWriter.begin_page` returns a `DeviceWrapper`, which is then passed to :meth:`Story.draw`.

**Class API**

.. class:: Device
.. class:: DeviceWrapper

.. method:: __init__(pixmap, clip, /)

Constructor for a pixel map (draw) device.

:arg pixmap: the pixmap to render to.
:type pixmap: :ref:`Pixmap`

.. method:: __init__(self, object, clip)
:arg clip: an `IRect` to restrict rendering to a certain area of the page. If the complete page is required, specify ``None``. This argument must always be given.
:type clip: :data:`irect_like`

Constructor for either a pixel map or a display list device.
.. method:: __init__(displaylist, /)
:no-index:

:arg object: either a ``Pixmap`` or a ``DisplayList``.
:type object: :ref:`Pixmap` or :ref:`DisplayList`
Constructor for a display list device.

:arg clip: An optional `IRect` for ``Pixmap`` devices to restrict rendering to a certain area of the page. If the complete page is required, specify ``None``. For display list devices, this parameter must be omitted.
:type clip: :ref:`IRect`
:arg displaylist: a low-level |MuPDF| display list, i.e. the `this` attribute of a :ref:`DisplayList` (`mupdf.FzDisplayList`). A :ref:`DisplayList` object itself is not accepted.

.. method:: __init__(self, textpage, flags=0)
.. method:: __init__(textpage, flags, /)
:no-index:

Constructor for a text page device.

:arg textpage: ``TextPage`` object
:type textpage: :ref:`TextPage`
:arg textpage: a low-level |MuPDF| text page, i.e. the `this` attribute of a :ref:`TextPage` (`mupdf.FzStextPage`). A :ref:`TextPage` object itself is not accepted.

:arg int flags: control the way how text is parsed into the text page. Currently 3 options can be coded into this parameter, see :ref:`TextPreserve`. To set these options use something like `flags=0 | TEXT_PRESERVE_LIGATURES | ...`. This argument must always be given.

.. method:: __init__(device, /)
:no-index:

Wrap an existing low-level |MuPDF| device (`mupdf.FzDevice`). This is how :meth:`DocumentWriter.begin_page` creates its return value.

:arg int flags: control the way how text is parsed into the text page. Currently 3 options can be coded into this parameter, see :ref:`TextPreserve`. To set these options use something like `flags=0 | TEXT_PRESERVE_LIGATURES | ...`.
:arg device: a `mupdf.FzDevice`.

.. include:: footer.rst
16 changes: 8 additions & 8 deletions docs/displaylist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A display list is populated with objects from a page, usually by executing :meth

.. class:: DisplayList

.. method:: __init__(self, mediabox)
.. method:: __init__(self, mediabox, /)

Create a new display list.

Expand All @@ -39,17 +39,17 @@ A display list is populated with objects from a page, usually by executing :meth

:rtype: ``DisplayList``

.. method:: run(device, matrix, area)
.. method:: run(dw, m, area)

Run the display list through a device. The device will populate the display list with its "commands" (i.e. text extraction or image creation). The display list can later be used to "read" a page many times without having to re-interpret it from the document file.

You will most probably instead use one of the specialized run methods below -- :meth:`get_pixmap` or :meth:`get_textpage`.

:arg device: Device
:type device: :ref:`Device`
:arg dw: Device
:type dw: :ref:`Device`

:arg matrix: Transformation matrix to apply to the display list contents.
:type matrix: :ref:`Matrix`
:arg m: Transformation matrix to apply to the display list contents.
:type m: :ref:`Matrix`

:arg area: Only the part visible within this area will be considered when the list is run through the device.
:type area: :ref:`Rect`
Expand Down Expand Up @@ -77,13 +77,13 @@ A display list is populated with objects from a page, usually by executing :meth
:rtype: :ref:`Pixmap`
:returns: pixmap of the display list.

.. method:: get_textpage(flags)
.. method:: get_textpage(flags=3)

Run the display list through a text device and return a text page.

:arg int flags: control which information is parsed into a text page. Default value in PyMuPDF is `3 = TEXT_PRESERVE_LIGATURES | TEXT_PRESERVE_WHITESPACE`, i.e. :data:`ligatures` are **passed through**, white spaces are **passed through** (not translated to spaces), and images are **not included**. See :ref:`TextPreserve`.

:rtype: :ref:`TextPage`
:rtype: :ref:`pymupdf.mupdf.FzStextPage`
:returns: text page of the display list.

.. attribute:: rect
Expand Down
Loading
Loading