pdftools_toolbox.pdf.page
Classes
|
Represents a page, which may be either associated with a document or part of a document. |
- class pdftools_toolbox.pdf.page.Page(handle)[source]
Bases:
_NativeObject
Represents a page, which may be either associated with a document or part of a document. When the page is associated with a document, changes to the page are still possible. Any changes made to the page will be reflected in the associated document, after the page is appended to the document’s
pdftools_toolbox.pdf.document.Document.pages
. After a page is appended to a document’spdftools_toolbox.pdf.document.Document.pages
, the page becomes part of the document and no further changes to the page are possible.- static create(target_document: Document, size: Size) Page [source]
Create an empty page
The page is associated with the given target document but not yet part of it. It can be appended to the document’s
pdftools_toolbox.pdf.document.Document.pages
.- Parameters:
targetDocument (pdftools_toolbox.pdf.document.Document) – the output document with which the returned object is associated
size (pdftools_toolbox.geometry.real.size.Size) – the page size
- Returns:
the newly created page object
- Return type:
- Raises:
ValueError – if the targetDocument argument has already been closed
ValueError – if the targetDocument argument is read-only
- static copy(target_document: Document, page: Page, options: PageCopyOptions | None) Page [source]
Copy a page
Copy a page object from an input document to the given targetDocument. The returned object is associated with the given target document but not yet part of it. It can be appended to the document’s
pdftools_toolbox.pdf.document.Document.pages
.- Parameters:
targetDocument (pdftools_toolbox.pdf.document.Document) – the output document with which the returned object is associated
page (pdftools_toolbox.pdf.page.Page) – a page of a different document
options (Optional[pdftools_toolbox.pdf.page_copy_options.PageCopyOptions]) – the copy options
- Returns:
the copied page, associated with the current document.
- Return type:
- Raises:
OSError – Error reading from the source document or writing to the target document
pdftools_toolbox.corrupt_error.CorruptError – The source document is corrupt
pdftools_toolbox.conformance_error.ConformanceError – The conformance level of the source document is not compatible with the conformance level of the target document.
pdftools_toolbox.conformance_error.ConformanceError – The explicitly requested conformance level is PDF/A Level A (
pdftools_toolbox.pdf.conformance.Conformance.PDFA1A
,pdftools_toolbox.pdf.conformance.Conformance.PDFA2A
, orpdftools_toolbox.pdf.conformance.Conformance.PDFA3A
) and the copy optionpdftools_toolbox.pdf.page_copy_options.PageCopyOptions.copy_logical_structure
is not set.ValueError – if the targetDocument argument has already been closed
ValueError – if the targetDocument argument is read-only
ValueError – if the page object is not associated with an input document
ValueError – if the document associated with the page object has already been closed
ValueError – if the argument options has
pdftools_toolbox.pdf.page_copy_options.PageCopyOptions.form_fields
set topdftools_toolbox.pdf.forms.form_field_copy_strategy.FormFieldCopyStrategy.COPY
and the targetDocument contains form fields that have either been copied explicitly withpdftools_toolbox.pdf.forms.field_node.FieldNode.copy()
or created withpdftools_toolbox.pdf.forms.check_box.CheckBox.create()
,pdftools_toolbox.pdf.forms.combo_box.ComboBox.create()
,pdftools_toolbox.pdf.forms.comb_text_field.CombTextField.create()
,pdftools_toolbox.pdf.forms.general_text_field.GeneralTextField.create()
,pdftools_toolbox.pdf.forms.list_box.ListBox.create()
,pdftools_toolbox.pdf.forms.radio_button_group.RadioButtonGroup.create()
, orpdftools_toolbox.pdf.forms.sub_form.SubForm.create()
.ValueError – if the argument options has
pdftools_toolbox.pdf.page_copy_options.PageCopyOptions.unsigned_signatures
set topdftools_toolbox.pdf.copy_strategy.CopyStrategy.COPY
and the targetDocument contains form fields that have either been copied explicitly withpdftools_toolbox.pdf.forms.field_node.FieldNode.copy()
or created withpdftools_toolbox.pdf.forms.check_box.CheckBox.create()
,pdftools_toolbox.pdf.forms.combo_box.ComboBox.create()
,pdftools_toolbox.pdf.forms.comb_text_field.CombTextField.create()
,pdftools_toolbox.pdf.forms.general_text_field.GeneralTextField.create()
,pdftools_toolbox.pdf.forms.list_box.ListBox.create()
,pdftools_toolbox.pdf.forms.radio_button_group.RadioButtonGroup.create()
, orpdftools_toolbox.pdf.forms.sub_form.SubForm.create()
.ValueError – if options has
pdftools_toolbox.pdf.page_copy_options.PageCopyOptions.copy_outline_items
set to True and the targetDocument contains outline items that have been copied explicitly withpdftools_toolbox.pdf.navigation.outline_item.OutlineItem.copy()
.
- update_size(rectangle: Rectangle) None [source]
Update the page size to a specified rectangle.
Note that all page-related coordinates are normalized to the crop box of the page. Updating the page size thus changes the coordinate system, rendering all previously extracted coordinates invalid.
- Parameters:
rectangle (pdftools_toolbox.geometry.real.rectangle.Rectangle) – the rectangle to update the page size to.
- Raises:
StateError – if the owning document has already been closed
StateError – if the page has already been closed
OperationError – if the page is read-only
- rotate(rotate: Rotation) None [source]
Rotate the page by a multiple of 90 degrees.
- Parameters:
rotate (pdftools_toolbox.geometry.rotation.Rotation) – the desired rotation
- Raises:
StateError – if the owning document has already been closed
StateError – if the page has already been closed
OperationError – if the page is read-only
- property rotation: Rotation
The current page rotation
- Returns:
pdftools_toolbox.geometry.rotation.Rotation
- property size: Size
The visible size of the page (crop box).
The page size corresponds to the size of the crop box. Since all coordinates are normalized to the origin of the crop box, the normalized origin of the crop box is always (0,0) and thus only the size is required.
The crop box defines the region to which the contents of the page shall be clipped (cropped) when displayed or printed. Unlike the other boxes, the crop box has no defined meaning in terms of physical page geometry or intended use; it merely imposes clipping on the page contents. However, in the absence of additional information (such as imposition instructions specified in a JDF job ticket), the crop box determines how the page’s contents shall be positioned on the output medium. The default value is the page’s media box.
This property cannot be None.
- Returns:
pdftools_toolbox.geometry.real.size.Size
- Raises:
StateError – if the page has already been closed
- property media_box: Rectangle
The media box of the page.
The media box defines the boundaries of the physical medium on which the page is to be printed. It may include any extended area surrounding the finished page for bleed, printing marks, or other such purposes. It may also include areas close to the edges of the medium that cannot be marked because of physical limitations of the output device. Content falling outside this boundary may safely be discarded without affecting the meaning of the PDF file.
This property cannot be None.
- Returns:
pdftools_toolbox.geometry.real.rectangle.Rectangle
- Raises:
StateError – if the page has already been closed
- property bleed_box: Rectangle | None
The bleed box of the page.
The bleed box (PDF 1.3) defines the region to which the contents of the page shall be clipped when output in a production environment. This may include any extra bleed area needed to accommodate the physical limitations of cutting, folding, and trimming equipment. The actual printed page may include printing marks that fall outside the bleed box. The default value is the page’s crop box.
This property is None if the page contains no explicit bleed box.
- Returns:
Optional[pdftools_toolbox.geometry.real.rectangle.Rectangle]
- Raises:
StateError – if the page has already been closed
- property trim_box: Rectangle | None
The trim box of the page.
The trim box (PDF 1.3) defines the intended dimensions of the finished page after trimming. It may be smaller than the media box to allow for production-related content, such as printing instructions, cut marks, or colour bars. The default value is the page’s crop box.
This property is None if the page contains no explicit trim box.
- Returns:
Optional[pdftools_toolbox.geometry.real.rectangle.Rectangle]
- Raises:
StateError – if the page has already been closed
- property art_box: Rectangle | None
The art box of the page.
The art box (PDF 1.3) defines the extent of the page’s meaningful content (including potential white-space) as intended by the page’s creator. The default value is the page’s crop box.
This property is None if the page contains no explicit art box.
- Returns:
Optional[pdftools_toolbox.geometry.real.rectangle.Rectangle]
- Raises:
StateError – if the page has already been closed
- property content: Content
the page content.
If the page is writable, the content object can be used to apply new content on the page, for example overlays or underlays.
- Returns:
pdftools_toolbox.pdf.content.content.Content
- Raises:
StateError – if the page has already been closed
- property annotations: AnnotationList
the list of this page’s annotations.
Adding to this list results in an error:
IllegalState if the list has already been closed
UnsupportedOperation if the document is read-only
IllegalArgument - if the given annotation is None - if the given annotation object has already been closed - if the given annotation does not belong to the same document as the list - if the given annotation is already associated with a page
This list does not support removing or setting elements or clearing.
- Returns:
pdftools_toolbox.pdf.annotations.annotation_list.AnnotationList
- Raises:
StateError – if the page has already been closed
- property links: LinkList
the list of this page’s links.
Adding to this list results in an error:
IllegalState if the list has already been closed
UnsupportedOperation if the document is read-only
IllegalArgument - if the given link is None - if the given link object has already been closed - if the given link does not belong to the same document as the list - if the given link is already associated with a page
This list does not support removing or setting elements or clearing.
- Returns:
pdftools_toolbox.pdf.navigation.link_list.LinkList
- Raises:
StateError – if the page has already been closed
- property widgets: WidgetList
the list of this page’s form field widgets.
Adding to this list results in an error:
IllegalState if the list has already been closed
UnsupportedOperation if the document is read-only
IllegalArgument - if the given widget is None - if the given widget object has already been closed - if the given widget does not belong to the same document as the list - if the given widget is already associated with a page
This list does not support removing or setting elements or clearing.
- Returns:
pdftools_toolbox.pdf.forms.widget_list.WidgetList
- Raises:
StateError – if the page has already been closed
- property metadata: Metadata | None
the metadata of the page.
If the document is writable, the metadata object will be writable too and all changes to the metadata object are reflected in the document.
This property is None if the page has not metadata.
- Returns:
Optional[pdftools_toolbox.pdf.metadata.Metadata]
- Raises:
StateError – if the document has already been closed
- property page_label: str
Page label
The label for this page. A page does not have to have a label and if it doesn’t this property will be an empty string.
If it exists, a page label is designed to replace the page number in visual presentations and consists of an optional prefix and a number. Number can be in one of several styles (arabic, Roman, alphabetic) and starts at an arbitrary number for a range of pages.
Page labels are used to set distinct names or numbers, most often for preface, appendices and similar sections of the document.
- Returns:
str
- Raises:
StateError – If the document has already been closed.