File: PDFPage.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 (273 lines) | stat: -rw-r--r-- 6,293 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
.. default-domain:: js

.. highlight:: javascript

PDFPage
+++++++

A PDFPage inherits `Page`, so its interface is also available for
PDFPage objects.

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

.. class:: PDFPage

	|no_new|

Instances of this class are returned by :js:meth:`~Document.prototype.loadPage` called on a `PDFDocument`.

Static properties
-----------------

|only_mupdfjs|

.. data:: PDFPage.REDACT_IMAGE_NONE

	for no image redactions

.. data:: PDFPage.REDACT_IMAGE_REMOVE

	to redact entire images

.. data:: PDFPage.REDACT_IMAGE_PIXELS

	for redacting just the covered pixels

.. data:: PDFPage.REDACT_IMAGE_UNLESS_INVISIBLE

	only redact visible images

.. data:: PDFPage.REDACT_LINE_ART_NONE

	for no line art redactions

.. data:: PDFPage.REDACT_LINE_ART_REMOVE_IF_COVERED

	redacts line art if covered

.. data:: PDFPage.REDACT_LINE_ART_REMOVE_IF_TOUCHED

	redacts line art if touched

.. data:: PDFPage.REDACT_TEXT_REMOVE

	to redact text

.. data:: PDFPage.REDACT_TEXT_NONE

	for no text redaction

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

.. method:: PDFPage.prototype.getObject()

	Get the underlying `PDFObject` for a `PDFPage`.

	:returns: `PDFObject`

	.. code-block::

		var obj = page.getObject()

.. method:: PDFPage.prototype.getAnnotations()

	Returns an array of all annotations on the page.

	:returns: Array of `PDFAnnotation`

	.. code-block::

		var annots = page.getAnnotations()

.. method:: PDFPage.prototype.getWidgets()

	Returns an array of all widgets on the page.

	:returns: Array of `PDFWidget`

	.. code-block::

		var widgets = page.getWidgets()

.. method:: PDFPage.prototype.setPageBox(box, rect)

	Sets the type of box required for the page.

	:param string box: The :term:`page box` type to change.
	:param Rect rect: The new desired dimensions.

	.. code-block::

		page.setPageBox("ArtBox", [10, 10, 585, 832])

.. method:: PDFPage.prototype.createAnnotation(type)

	Create a new blank annotation of a given annotation type.

	:param string type: The :term:`annotation type` to create.

	:returns: `PDFAnnotation`.

	.. code-block::

		var annot = page.createAnnotation("Text")

.. method:: PDFPage.prototype.deleteAnnotation(annot)

	Delete a `PDFAnnotation` from the page.

	:param PDFAnnotation annot:

	.. code-block::

		var annots = getAnnotations()
		page.delete(annots[0])

.. method:: PDFPage.prototype.update()

	Loop through all annotations of the page and update them.

	Returns true if re-rendering is needed because at least one
	annotation was changed (due to either events or Javascript
	actions or annotation editing).

	:returns: boolean

	.. code-block::

		// edit an annotation
		var updated = page.update()

.. method:: PDFPage.prototype.toPixmap(matrix, colorspace, alpha, showExtras, usage, box)

	Render the page into a `Pixmap` with the PDF "usage" and :term:`page box`.

	:param Matrix matrix: The transformation matrix.
	:param ColorSpace colorspace: The desired colorspace.
	:param boolean alpha: Whether or not the returned pixmap will use alpha.
	:param boolean renderExtra: Whether annotations and widgets should be rendered. Defaults to true.
	:param string usage: If the output is destined for viewing or printing. Defaults to "View".
	:param string box: Default is "CropBox".

	:returns: `Pixmap`

	.. code-block::

		var pixmap = page.toPixmap(
			mupdf.Matrix.identity,
			mupdf.ColorSpace.DeviceRGB,
			true,
			false,
			"View",
			"CropBox"
		)

.. method:: PDFPage.prototype.applyRedactions(blackBoxes, imageMethod, lineArtMethod, textMethod)

	Applies all the Redaction annotations on the page.

	Redactions are a special type of annotation used to permanently remove (or
	"redact") content from a PDF.

	:param boolean blackBoxes: Whether to use black boxes at each redaction or not.
	:param number imageMethod: Default is `PDFPage.REDACT_IMAGE_PIXELS`.
	:param number lineArtMethod: Default is `PDFPage.REDACT_LINE_ART_REMOVE_IF_COVERED`.
	:param number textMethod: Default is `PDFPage.REDACT_TEXT_REMOVE`.

	Once redactions are added to a page you can *apply* them, which is an
	irreversible action, thus it is a two step process as follows:

	.. code-block::

		var annot1 = page.createAnnotation("Redaction")
		annot1.setRect([0, 0, 500, 100])
		var annot2 = page.createAnnotation("Redaction")
		annot2.setRect([0, 600, 500, 700])
		page.applyRedactions(true, mupdf.PDFPage.REDACT_IMAGE_NONE)

.. method:: PDFPage.prototype.process(processor)

	|only_mutool|

	Run through the page contents stream and call methods on the
	supplied `PDFProcessor`.

	:param PDFProcessor processor: User defined function callback object.

	.. code-block:: javascript

		pdfPage.process(processor)

.. method:: PDFPage.prototype.getTransform()

	Return the transform from MuPDF page space (upper left page origin,
	y descending, 72 dpi) to PDF user space (arbitrary page origin, y
	ascending, UserUnit dpi).

	:returns: `Rect`

	.. code-block:: javascript

		var transform = pdfPage.getTransform()

.. method:: PDFPage.prototype.createSignature(name)

	|only_mutool|

	Create a new signature widget with the given name as field
	label.

	:param string name: The desired field label.

	:returns: `PDFWidget`

	.. code-block:: javascript

		var signatureWidget = pdfPage.createSignature("test")

.. method:: PDFPage.prototype.countAssociatedFiles()

	|only_mutool|

	Return the number of :term:`associated files <associated file>`
	associated with this page. Note that this is the number of
	files associated with this page, not necessarily the
	total number of files associated with elements throughout the
	entire document.

	:returns: number

	.. code-block:: javascript

		var count = pdfPage.countAssociatedFiles()

.. method:: PDFPage.prototype.associatedFile(n)

	|only_mutool|

	Return the :term:`file specification` object that represents the nth
	Associated File on this page.

	``n`` should be in the range ``0 <= n < countAssociatedFiles()``.

	Returns null if no associated file exists or index is out of range.

	:returns: `PDFObject` | null

	.. code-block:: javascript

		var obj = pdfPage.associatedFile(0)

.. method:: PDFPage.prototype.clip(rect)

	|only_mutool|

	Clip the page to the given rectangle.

	:param Rect rect: The new desired dimensions.

	.. code-block:: javascript

		pdfPage.clip([0, 0, 200, 300])