File: Page.rst

package info (click to toggle)
mupdf 1.27.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,224 kB
  • sloc: ansic: 335,320; python: 20,906; java: 7,520; javascript: 2,213; makefile: 1,152; xml: 675; cpp: 639; sh: 513; cs: 307; awk: 10; sed: 7; lisp: 3
file content (244 lines) | stat: -rw-r--r-- 6,437 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
.. default-domain:: js

.. highlight:: javascript

Page
====

A Page object is a page that has been loaded from a `Document`.

Page objects that belong to a `PDFDocument`, also provide
the interface described in `PDFPage`.

Constructors
------------

.. class:: Page

	|no_new|

Page instances are returned by `Document.prototype.loadPage()`.

Constants
---------

The :term:`page box` types:

.. data:: Page.MEDIA_BOX
.. data:: Page.CROP_BOX
.. data:: Page.BLEED_BOX
.. data:: Page.TRIM_BOX
.. data:: Page.ART_BOX

Instance methods
----------------

.. method:: Page.prototype.getBounds(box)

	Returns a rectangle describing the page dimensions.

	:param string box: Which :term:`page box` to query.

	:returns: `Rect`

	.. code-block::

		var rect = page.getBounds()

.. method:: Page.prototype.run(device, transform)

	Calls device functions for all the contents on the page, using the
	specified transform.

	The device can be one of the built-in devices (`DrawDevice` and `DisplayListDevice`)
	or a Javascript `Device`.

	The matrix transforms coordinates from user space to device space.

	:param Device device: The device object.
	:param Matrix matrix: The transformation matrix.

	.. code-block::

		page.run(dev, mupdf.Matrix.identity)

.. method:: Page.prototype.runPageContents(device, transform)

	This is the same as the `Page.prototype.run()` method above but it only
	runs the page itself and omits annotations and widgets.

	:param Device device: The device object.
	:param Matrix matrix: The transformation matrix.

	.. code-block::

		page.runPageContents(dev, mupdf.Matrix.identity)

.. method:: Page.prototype.runPageAnnots(device, transform)

	This is the same as the `Page.prototype.run()` method above but it only
	runs the page annotations.

	:param Device device: The device object.
	:param Matrix matrix: The transformation matrix.

	.. code-block::

		page.runPageAnnots(dev, mupdf.Matrix.identity)

.. method:: Page.prototype.runPageWidgets(device, transform)

	This is the same as the `Page.prototype.run()` method above but it only
	runs the page widgets.

	:param Device device: The device object.
	:param Matrix matrix: The transformation matrix.

	.. code-block::

		page.runPageWidgets(dev, mupdf.Matrix.identity)

.. method:: Page.prototype.toPixmap(matrix, colorspace, alpha, showExtras)

	Render the page into a `Pixmap` using the specified transform
	matrix and colorspace. If ``alpha`` is ``true``, the page will be drawn
	on a transparent background, otherwise white. If ``showExtras`` is
	``true`` then the operation will include any page annotations and/or
	widgets.

	:param Matrix matrix: The transformation matrix.
	:param ColorSpace colorspace: The desired colorspace of the returned pixmap.
	:param boolean alpha: Whether the resulting pixmap should have an alpha component. Defaults to ``true``.
	:param boolean showExtras: Whether to render annotations and widgets. Defaults to ``true``.

	:returns: `Pixmap`

	.. code-block::

		var pixmap = page.toPixmap(mupdf.Matrix.identity, mupdf.ColorSpace.DeviceRGB, true, true)

.. method:: Page.prototype.toDisplayList(showExtras)

	Record the contents on the page into a `DisplayList`. If
	``showExtras`` is ``true`` then the operation will include all
	annotations and/or widgets on the page.

	:param boolean showExtras: Whether to render annotations and widgets. Defaults to ``true``.

	:returns: `DisplayList`

	.. code-block::

		var displayList = page.toDisplayList(true)

.. method:: Page.prototype.toStructuredText(options)

	Extract the text on the page into a `StructuredText` object.

	:param string options:
		See :doc:`/reference/common/stext-options`.

	:returns: `StructuredText`

	.. code-block::

		var sText = page.toStructuredText("preserve-whitespace")

.. method:: Page.prototype.search(needle, maxHits)

	Search the page text for all instances of the ``needle`` value,
	and return an array of search hits.

	Each search hit is an array of `Quad`, each corresponding
	to a character in the search hit.

	:param string needle: The text to search for.
	:param number options: Optional options for the search. A logical or of options such as `StructuredText.SEARCH_EXACT`.

	:returns: Array of Array of `Quad`

	.. code-block::

		var results = page.search("my search phrase")

.. method:: Page.prototype.getLinks()

	Return an array of all the links on the page. If there are no
	links then an empty array is returned.

	Each link is an object with a 'bounds' property, and either a
	'page' or 'uri' property, depending on whether it's an internal or
	external link.

	:returns: Array of `Link`

	.. code-block::

		var links = page.getLinks()
		var link = links[0]
		var linkDestination = doc.resolveLink(link)

.. method:: Page.prototype.createLink(rect, uri)

	Create a new link with the supplied metrics for the page, linking to the destination URI string.

	To create links to other pages within the document see the `Document.prototype.formatLinkURI` method.

	:param Rect rect: Rectangle specifying the active area on the page the link should cover.
	:param string destinationUri: A URI string describing the desired link destination.

	:returns: `Link`.

	.. code-block::

		// create a link to an external URL
		var link = page.createLink([0, 0, 100, 50], "https://example.com")

		// create a link to another page in the document
		var link = page.createLink([0, 100, 100, 150], "#page=1&view=FitV,0")

.. method:: Page.prototype.deleteLink(link)

	Delete the link from the page.

	:param Link link: The link to remove.

	.. code-block::

		page.deleteLink(link_obj)

.. method:: Page.prototype.getLabel()

	Returns the page number as a string using the numbering scheme of the document.

	:returns: string

	.. code-block::

		var label = page.getLabel()

.. method:: Page.prototype.isPDF()

	Returns ``true`` if the page is from a PDF document.

	:returns: boolean

	.. code-block::

		var isPDF = page.isPDF()

.. method:: Page.prototype.decodeBarcode(subarea, rotate)

	|only_mutool|

	Decodes a barcode detected on the page, and returns an object with
	properties for barcode type and contents.

	:param Rect subarea: Only detect barcode within subarea. Defaults to the entire page.
	:param number rotate: Degrees of rotation to rotate page before detecting barcode. Defaults to 0.

	:returns: Object with barcode information.

	.. code-block:: javascript

		var info = page.decodeBarcode(page.getBounds(), 0)