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
+19-3Lines changed: 19 additions & 3 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.
606
+
607
+
597
608
.. method:: reload_page(page)
598
609
599
610
* New in v1.16.10
@@ -924,14 +935,14 @@ For details on **embedded files** refer to Appendix 3.
924
935
925
936
.. method:: get_page_fonts(pno, full=False)
926
937
927
-
PDF only: Return a list of all fonts (directly or indirectly) referenced by the page.
938
+
PDF only: Return a list of all fonts (directly or indirectly) referenced by the page object definition.
:arg bool full: whether to also include the referencer's :data:`xref`. If *True*, the returned items are one entry longer. Use this option if you need to know, whether the page directly references the font. In this case the last entry is 0. If the font is referenced by an `/XObject` of the page, you will find its :data:`xref` here.
931
942
932
943
:rtype: list
933
944
934
-
:returns: a list of fonts referenced by this page. Each entry looks like
945
+
:returns: a list of fonts referenced by the object definition of the page. Each entry looks like
@@ -959,7 +970,12 @@ For details on **embedded files** refer to Appendix 3.
959
970
960
971
.. note::
961
972
* This list has no duplicate entries: the combination of :data:`xref`, *name* and *referencer* is unique.
962
-
* In general, this is a superset of the fonts actually in use by this page. The PDF creator may e.g. have specified some global list, of which each page only makes partial use.
973
+
* In general, this is a true superset of the fonts actually in use by this page. The PDF creator may e.g. have specified some global list, of which each page make only partial use.
974
+
* Be aware that font names returned by some variants of :meth:`Page.get_text` (respectively :ref:`TextPage` methods) need not (exactly) equal the base font name shown here. Reasons for any differences include:
975
+
976
+
- This method always shows any subset prefixes (the pattern ``ABCDEF+``), whereas text extractions do not do this by default.
977
+
- Text extractions use the base library to access the font name, which has a length cap of 31 bytes and generally interrogates the font file binary to access the name. Method ``get_page_fonts()`` however looks at the PDF definition source.
978
+
- Text extractions work for all supported document types in exactly the same way -- not just for PDFs. Consequently they do not contain PDF-specifics.
Copy file name to clipboardExpand all lines: docs/page.rst
+28-8Lines changed: 28 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,6 +106,7 @@ In a nutshell, this is what you can do with PyMuPDF:
106
106
:meth:`Page.load_widget` PDF only: load a specific field
107
107
:meth:`Page.load_links` return the first link on a page
108
108
:meth:`Page.new_shape` PDF only: create a new :ref:`Shape`
109
+
:meth:`Page.recolor` PDF only: change the colorspace of objects
109
110
:meth:`Page.remove_rotation` PDF only: set page rotation to 0
110
111
:meth:`Page.replace_image` PDF only: replace an image
111
112
:meth:`Page.search_for` search for a string
@@ -545,23 +546,34 @@ In a nutshell, this is what you can do with PyMuPDF:
545
546
546
547
.. method:: add_stamp_annot(rect, stamp=0)
547
548
548
-
PDF only: Add a "rubber stamp" like annotation to e.g. indicate the document's intended use ("DRAFT", "CONFIDENTIAL", etc.).
549
+
PDF only: Add a "rubber stamp" annotation to e.g. indicate the document's intended use ("DRAFT", "CONFIDENTIAL", etc.). The parameter may be either an integer to select text from a predefined array of standard texts or an image.
549
550
550
551
:arg rect_like rect: rectangle where to place the annotation.
552
+
:arg multiple stamp: The following options are available:
553
+
554
+
* The id number (int) of the stamp text. For available stamps see :ref:`StampIcons`.
555
+
556
+
* A string specifying an image file path.
551
557
552
-
:arg int stamp: id number of the stamp text. For available stamps see :ref:`StampIcons`.
558
+
* A ``bytes``, ``bytearray`` or ``io.BytesIO`` object for an image in memory.
553
559
554
-
.. note::
560
+
* A :ref:`Pixmap`.
561
+
562
+
1. **Text-based stamps**
555
563
556
-
* 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.
564
+
* :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.
557
565
* The font chosen is "Times Bold" and the text will be upper case.
558
-
* The appearance can be changed using :meth:`Annot.set_opacity` and by setting the "stroke" color (no "fill" color supported).
559
-
* 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.
566
+
* 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.
560
567
568
+
.. image:: images/img-stampannot.*
561
569
562
-
.. image:: images/img-stampannot.*
563
-
:scale:80
570
+
2. **Image-based stamps**
564
571
572
+
* The image is scaled to fit into the rectangle `rect` such that the image's center and the center of `rect` coincide. The aspect ratio of the image is preserved, so the image may not fill the entire rectangle. However, at least one of the given rectangle's width or height are fully covered.
573
+
* The annotation can be modified via :meth:`Annot.set_opacity`. This method therefore is a way to display images transparently even if no alpha channel is present.
574
+
* Setting colors has no effect on image stamps.
575
+
* Rotating image-based stamps **is not supported**. Setting the rotation may lead to unexpected results.
576
+
565
577
.. method:: add_widget(widget)
566
578
567
579
PDF only: Add a PDF Form field ("widget") to a page. This also **turns the PDF into a Form PDF**. Because of the large amount of different options available for widgets, we have developed a new class :ref:`Widget`, which contains the possible PDF field attributes. It must be used for both, form field creation and updates.
@@ -1937,6 +1949,14 @@ In a nutshell, this is what you can do with PyMuPDF:
1937
1949
1938
1950
:arg int rotate: An integer specifying the required rotation in degrees. Must be an integer multiple of 90. Values will be converted to one of 0, 90, 180, 270.
1939
1951
1952
+
.. method:: recolor(components=1)
1953
+
1954
+
PDF only: Change the colorspace components of all objects on page.
1955
+
1956
+
: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 grayscale. If a page is already grayscale, the method will not cause visible changes -- independent of the value of ``components``.
1957
+
1958
+
These changes are **permanent** and cannot be reverted.
1959
+
1940
1960
.. method:: remove_rotation()
1941
1961
1942
1962
PDF only: Set page rotation to 0 while maintaining appearance and page content.
0 commit comments