Source code for pdftools_toolbox.pdf.navigation.fit_rectangle_destination

from __future__ import annotations
import io
from typing import List, Iterator, Tuple, Optional, Any, TYPE_CHECKING, Callable
from ctypes import *
from datetime import datetime
from numbers import Number
from pdftools_toolbox.internal import _lib
from pdftools_toolbox.internal.utils import _string_to_utf16, _utf16_to_string
from pdftools_toolbox.internal.streams import _StreamDescriptor, _NativeStream
from pdftools_toolbox.internal.native_base import _NativeBase
from pdftools_toolbox.internal.native_object import _NativeObject

import pdftools_toolbox.internal
import pdftools_toolbox.pdf.navigation.direct_destination

if TYPE_CHECKING:
    from pdftools_toolbox.pdf.document import Document
    from pdftools_toolbox.pdf.page import Page
    from pdftools_toolbox.geometry.real.rectangle import Rectangle

else:
    Document = "pdftools_toolbox.pdf.document.Document"
    Page = "pdftools_toolbox.pdf.page.Page"
    Rectangle = "pdftools_toolbox.geometry.real.rectangle.Rectangle"


[docs] class FitRectangleDestination(pdftools_toolbox.pdf.navigation.direct_destination.DirectDestination): """ A destination that fits a specified area of a page into the viewport. Note: Many PDF viewers support different viewing modes like "fit page" or "fit width". A :class:`pdftools_toolbox.pdf.navigation.fit_rectangle_destination.FitRectangleDestination` will change the current viewing mode to standard mode in those viewers, i.e. deactivate any special mode like "fit page" or "fit width". Changing the viewing mode is usually not very well received by users and thus a :class:`pdftools_toolbox.pdf.navigation.location_zoom_destination.LocationZoomDestination` should be preferred in most cases. """
[docs] @staticmethod def create(target_document: Document, page: Page, rectangle: Rectangle) -> Optional[FitRectangleDestination]: """ Create a new FitRectangleDestination The returned object is not yet used on any page, but it is associated with the given target document. Args: targetDocument (pdftools_toolbox.pdf.document.Document): The output document with which the returned object is associated page (pdftools_toolbox.pdf.page.Page): The page in the document that this destination is pointing to. rectangle (pdftools_toolbox.geometry.real.rectangle.Rectangle): The rectangle that is displayed in the viewport. See property :attr:`pdftools_toolbox.pdf.navigation.fit_rectangle_destination.FitRectangleDestination.rectangle` for more information. Returns: Optional[pdftools_toolbox.pdf.navigation.fit_rectangle_destination.FitRectangleDestination]: The newly created destination object. Raises: ValueError: if the `targetDocument` argument has already been closed ValueError: if the `targetDocument` argument is read-only ValueError: if the `targetDocument`differs from the document associated with `page` ValueError: If the document associated with the `page` argument has already been closed """ from pdftools_toolbox.pdf.document import Document from pdftools_toolbox.pdf.page import Page from pdftools_toolbox.geometry.real.rectangle import Rectangle if not isinstance(target_document, Document): raise TypeError(f"Expected type {Document.__name__}, but got {type(target_document).__name__}.") if not isinstance(page, Page): raise TypeError(f"Expected type {Page.__name__}, but got {type(page).__name__}.") if not isinstance(rectangle, Rectangle): raise TypeError(f"Expected type {Rectangle.__name__}, but got {type(rectangle).__name__}.") _lib.PtxPdfNav_FitRectangleDestination_Create.argtypes = [c_void_p, c_void_p, POINTER(Rectangle)] _lib.PtxPdfNav_FitRectangleDestination_Create.restype = c_void_p ret_val = _lib.PtxPdfNav_FitRectangleDestination_Create(target_document._handle, page._handle, rectangle) if ret_val is None: _NativeBase._throw_last_error() return None return FitRectangleDestination._create_dynamic_type(ret_val)
@property def rectangle(self) -> Rectangle: """ The rectangle that is displayed in the viewport. Returns: pdftools_toolbox.geometry.real.rectangle.Rectangle Raises: StateError: the object has already been closed. StateError: the associated document has already been closed. """ from pdftools_toolbox.geometry.real.rectangle import Rectangle _lib.PtxPdfNav_FitRectangleDestination_GetRectangle.argtypes = [c_void_p, POINTER(Rectangle)] _lib.PtxPdfNav_FitRectangleDestination_GetRectangle.restype = c_bool ret_val = Rectangle() if not _lib.PtxPdfNav_FitRectangleDestination_GetRectangle(self._handle, byref(ret_val)): _NativeBase._throw_last_error(False) return ret_val @staticmethod def _create_dynamic_type(handle): return FitRectangleDestination._from_handle(handle) @classmethod def _from_handle(cls, handle): """ Internal factory method for constructing an instance using an internal handle. This method creates an instance of the class by bypassing the public constructor. """ instance = FitRectangleDestination.__new__(cls) # Bypass __init__ instance._initialize(handle) return instance def _initialize(self, handle): super()._initialize(handle)