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
Copy file name to clipboardExpand all lines: docs/document.rst
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,6 +96,7 @@ For details on **embedded files** refer to Appendix 3.
96
96
:meth:`Document.pdf_catalog` PDF only: :data:`xref` of catalog (root)
97
97
:meth:`Document.pdf_trailer` PDF only: trailer source
98
98
:meth:`Document.prev_location` return (chapter, pno) of preceding page
99
+
:meth:`Document.recolor` PDF only: execute :meth:`Page.recolor` for all pages
99
100
:meth:`Document.reload_page` PDF only: provide a new copy of a page
100
101
:meth:`Document.resolve_names` PDF only: Convert destination names into a Python dict
101
102
:meth:`Document.save` PDF only: save the document
@@ -594,6 +595,16 @@ For details on **embedded files** refer to Appendix 3.
594
595
595
596
To maintain a consistent API, for document types not supporting a chapter structure (like PDFs), :attr:`Document.chapter_count` is 1, and pages can also be loaded via tuples *(0, pno)*. See this [#f3]_ footnote for comments on performance improvements.
596
597
598
+
599
+
.. method:: recolor(components=1)
600
+
601
+
PDF only: Change the color component counts for all object types text, image and vector graphics for all pages.
602
+
603
+
:arg int components: desired color space indicated by the number of color components: 1 = DeviceGRAY, 3 = DeviceRGB, 4 = DeviceCMYK.
604
+
605
+
The typical use case is 1 (DeviceGRAY) which converts the PDF to grayscale.
PDF only: Add a "rubber stamp"like annotation to e.g. indicate the document's intended use ("DRAFT", "CONFIDENTIAL", etc.).
541
+
PDF only: Add a "rubber stamp"-like annotation to e.g. indicate the document's intended use ("DRAFT", "CONFIDENTIAL", etc.). Instead of text, an image may also be shown.
542
542
543
543
:arg rect_like rect: rectangle where to place the annotation.
544
-
545
544
:arg int stamp: id number of the stamp text. For available stamps see :ref:`StampIcons`.
545
+
:arg multiple image: if not ``None``, an image specification is assumed and the ``stamp`` parameter will be ignored. Valid argument types are
546
+
547
+
* a string specifying an image file path,
548
+
* a ``bytes``, ``bytearray`` or ``io.BytesIO`` object for an image in memory, and
549
+
* a :ref:`Pixmap`.
550
+
551
+
1. **Text-based stamps**
546
552
547
-
.. note::
548
-
549
-
* The stamp's text and its border line will automatically be sized and be put horizontally and vertically centered in the given rectangle. :attr:`Annot.rect` is automatically calculated to fit the given **width** and will usually be smaller than this parameter.
553
+
* :attr:`Annot.rect` is automatically calculated as the largest rectangle with an aspect ratio of ``width/height = 3.8`` that fits in the provided ``rect``. Its position is vertically and horizontally centered.
550
554
* The font chosen is "Times Bold" and the text will be upper case.
551
-
* The appearance can be changed using :meth:`Annot.set_opacity` and by setting the "stroke" color (no "fill" color supported).
552
-
* This can be used to create watermark images: on a temporary PDF page create a stamp annotation with a low opacity value, make a pixmap from it with *alpha=True* (and potentially also rotate it), discard the temporary PDF page and use the pixmap with :meth:`insert_image` for your target PDF.
555
+
* The appearance can be modified using :meth:`Annot.set_opacity` and by setting the "stroke" color. By PDF specification, stamp annotations have no "fill" color.
556
+
557
+
.. image:: images/img-stampannot.*
553
558
559
+
2. **Image-based stamps**
554
560
555
-
.. image:: images/img-stampannot.*
556
-
:scale:80
561
+
* At first, a rectangle is computed like for text stamps: vertically and horizontally centered, aspect ratio ``width/height = 3.8``.
562
+
* Into that rectangle, the image will be inserted aligned left and vertically centered. The resulting image boundary box becomes :attr:`Annot.rect`.
563
+
* The annotation can be modified via :meth:`Annot.set_opacity`. This is a way to display images without alpha channel with transparency. Setting colors has no effect on image stamps.
564
+
565
+
.. image:: images/img-imagestamp.*
557
566
558
567
.. method:: add_widget(widget)
559
568
@@ -1929,7 +1938,7 @@ In a nutshell, this is what you can do with PyMuPDF:
1929
1938
1930
1939
PDF only: Change the colorspace components of all objects on page.
1931
1940
1932
-
:arg int components: The desired count of color components. Must be one of 1, 3 or 4, which results in color space DeviceGray, DeviceRGB and DeviceCMYK respectively. The method affects text, images and vector graphics. For instance, with the default value 1, a page will be converted to gray-scale.
1941
+
:arg int components: The desired count of color components. Must be one of 1, 3 or 4, which results in color spaces DeviceGray, DeviceRGB or DeviceCMYK respectively. The method affects text, images and vector graphics. For instance, with the default value 1, a page will be converted to gray-scale.
1933
1942
1934
1943
The changes made are **permanent** and cannot be reverted.
0 commit comments