PDFView

Swift

@available(iOS 13.0, *)
public struct PDFView : View

Wraps a PDFViewController into a SwiftUI container. Wrap the PDFView into a NavigationView to get the default top toolbar.

  • The observed document.

    Declaration

    Swift

    public var document: ObservedObject<Document>?
  • Initialize the main PSPDFKit view container.

    Declaration

    Swift

    public init(document: ObservedObject<Document>? = nil,
                pageIndex: Binding<PageIndex>? = nil,
                viewMode: Binding<ViewMode>? = nil,
                selectedAnnotations: Binding<[Annotation]>? = nil,
                actionEventPublisher: PassthroughSubject<ActionEvent, Never>? = nil,
                configuration: PDFConfiguration? = nil)

    Parameters

    document

    The document as observed object. The view can change the document for various actions.

    pageIndex

    Binding to get/set the current page index.

    viewMode

    Binding to get/set the document view mode.

    selectedAnnotations

    Binding to get/set the currently selected annotations.

    actionEventPublisher

    A publisher to pass in to trigger actions in the view.

    configuration

    The initial configuration

  • Initialize the main PSPDFKit view container.

    Declaration

    Swift

    public init(document: ObservedObject<Document>? = nil,
                pageIndex: Binding<PageIndex>? = nil,
                viewMode: Binding<ViewMode>? = nil,
                selectedAnnotations: Binding<[Annotation]>? = nil,
                actionEventPublisher: PassthroughSubject<ActionEvent, Never>? = nil,
                configurationBuilder: @escaping (PDFConfigurationBuilder) -> Void)

    Parameters

    document

    The document as observed object. The view can change the document for various actions.

    pageIndex

    Binding to get/set the current page index.

    viewMode

    Binding to get/set the document view mode.

    selectedAnnotations

    Binding to get/set the currently selected annotations.

    actionEventPublisher

    A publisher to pass in to trigger actions in the view.

    configurationBuilder

    A closure to modify the initial configuration.

  • Declaration

    Swift

    public var body: some View { get }
  • Various events that are exposed to trigger actions. Send these action events on the actionEventPublisher provided to PDFView.

    See more

    Declaration

    Swift

    public enum ActionEvent
  • Update arbitrary configuration properties via a PDFConfigurationBuilder closure.

    Declaration

    Swift

    public func updateConfiguration(builder builderBlock: @escaping (PDFConfigurationBuilder) -> Void) -> PDFView
  • Update arbitrary configuration properties of the used PDFViewController.

    Declaration

    Swift

    public func updateControllerConfiguration(block: @escaping (PDFViewController) -> Void) -> PDFView
  • Set a page mode defined in the enum. Defaults to .automatic. Reloads the view, unless it is set while rotation is active. Thus, one can customize the size change behavior by setting this within a size transition animation block. Ignored when pageTransition is set to PageTransition.scrollContinuous.

    Declaration

    Swift

    public func pageMode(_ pageMode: PageMode) -> PDFView
  • Defines the page transition. Defaults to .scrollPerSpread.

    Declaration

    Swift

    public func pageTransition(_ pageTransition: PageTransition) -> PDFView
  • Shows first document page alone as “cover mode”. Defaults to true.

    Declaration

    Swift

    public func firstPageAlwaysSingle(_ firstPageAlwaysSingle: Bool) -> PDFView
  • Controls whether spreads can grow larger than the actual view. Defaults to .adaptive. This can be helpful on smaller screens to make the content more readable.

    @note This property has no effect if the page transition is anything but PageTransition.scrollPerSpread or PageTransition.scrollContinuous.

    Declaration

    Swift

    public func spreadFitting(_ spreadFitting: PDFConfiguration.SpreadFitting) -> PDFView
  • Background color behind the page view. Defaults to a dynamic color on iOS 13 and above which matches the current UIUserInterfaceStyle. Falls back to dark gray color on versions prior iOS 13.

    Declaration

    Swift

    public func backgroundColor(_ backgroundColor: UIColor) -> PDFView
  • Page scrolling direction. Defaults to .horizontal. Only relevant for scrolling page transitions.

    Declaration

    Swift

    public func scrollDirection(_ scrollDirection: ScrollDirection) -> PDFView
  • Minimum zoom scale. Defaults to 1.

    Declaration

    Swift

    public func minimumZoomScale(_ minimumZoomScale: Float) -> PDFView
  • Maximum zoom scale for the scrollview. Defaults to 20.

    Declaration

    Swift

    public func maximumZoomScale(_ maximumZoomScale: Float) -> PDFView
  • Set the default link action for pressing on LinkAnnotations. Default is .openSafari.

    Declaration

    Swift

    public func linkAction(_ linkAction: LinkAction) -> PDFView
  • May be used to customize other displayed menu actions when text is selected. Defaults to .search|.define|.actionSpeak|.actionShare|.actionCopy|.actionAnnotationCreation.

    Declaration

    Swift

    public func allowedMenuActions(_ allowedMenuActions: TextSelectionMenuAction) -> PDFView
  • Allows text selection. Defaults to true.

    @note This implies that the PDF file actually contains text glyphs. Sometimes text is represented via embedded images or vectors, in that case PSPDFKit can’t select it.

    Declaration

    Swift

    public func textSelectionEnabled(_ textSelectionEnabled: Bool) -> PDFView
  • Allows image selection. Defaults to true.

    @note This implies that the image is not in vector format. Only supports a subset of all possible image types in PDF. @warning Will only work if textSelectionEnabled is also set to true.

    Declaration

    Swift

    public func imageSelectionEnabled(_ imageSelectionEnabled: Bool) -> PDFView
  • Modify what annotations are editable and can be created. Set to nil to completely disable annotation editing/creation. Defaults to all available annotation strings.

    In the case of .widget, whether that type is included in editableAnnotationTypes determines whether users can interact with PDF forms to edit form field values rather than editing the form elements themselves. In other words, editing the properties like background color or the position of form elements on the page is not supported.

    @warning Some annotation types are only behaviorally different in PSPDFKit but are mapped to basic annotation types, so adding those will only change the creation of those types, not editing. Example: If you add .ink but not .signature, signatures added in previous session will still be editable (since they are ink annotations). On the other hand, if you set .signature but not .ink, then your newly created signatures will not be movable.

    @see PSPDFAnnotation.h for additional comments.

    Declaration

    Swift

    public func editableAnnotationTypes(_ editableAnnotationTypes: Set<Annotation.Tool>) -> PDFView
  • Manages the show/hide mode of the user interface view. Defaults to .automaticNoFirstLastPage. @note The user interface view consists of the thumbnail view at the bottom and the page/document label.

    Declaration

    Swift

    public func userInterfaceViewMode(_ userInterfaceViewMode: UserInterfaceViewMode) -> PDFView
  • Enables/Disables the bottom document site position overlay. Defaults to true.

    Declaration

    Swift

    public func pageLabelEnabled(_ pageLabelEnabled: Bool) -> PDFView
  • Enable/disable the top document label overlay. Defaults to .adaptive: The document label is shown if there’s not enough space to set the navigation bar title instead.

    Declaration

    Swift

    public func documentLabelEnabled(_ documentLabelEnabled: AdaptiveConditional) -> PDFView
  • Automatically hides the user interface when the user starts scrolling to different pages in the document. Defaults to true.

    Declaration

    Swift

    public func shouldHideUserInterfaceOnPageChange(_ shouldHideUserInterfaceOnPageChange: Bool) -> PDFView
  • Controls whether a PDFViewController should show a page grabber on the edge of the screen to enable the user to quickly skim through the pages of a document.

    Defaults to false.

    Declaration

    Swift

    public func pageGrabberEnabled(_ pageGrabberEnabled: Bool) -> PDFView
  • If true, the status bar will be hidden when the user interface is hidden. Defaults to true.

    Declaration

    Swift

    public func shouldHideStatusBarWithUserInterface(_ shouldHideStatusBarWithUserInterface: Bool) -> PDFView
  • Defines if the floating redaction info button, that is shown when there are uncommitted redactions in the document, should be shown in the user interface view.

    Defaults to true, if the Redaction component is included in the license.

    @note Setting this property will have no effect if the Redaction component is not included in the license. @note When disabling this and you support redaction annotations, applying redactions will need to be handled manually.

    Declaration

    Swift

    public func shouldShowRedactionInfoButton(_ shouldShowRedactionInfoButton: Bool) -> PDFView
  • Whether the usage hint alert should be shown the first time the user selects the redaction tool. Defaults to true, if the Redaction component is included in the license.

    @note Setting this property will have no effect if the Redaction component is not included in the license.

    Declaration

    Swift

    public func redactionUsageHintEnabled(_ redactionUsageHintEnabled: Bool) -> PDFView
  • Shows a floating back button in the lower part of the screen. Used to navigate back to the origin page when navigating via PDF actions. Defaults to true.

    Declaration

    Swift

    public func showBackActionButton(_ showBackActionButton: Bool) -> PDFView
  • Shows a floating forward button in the lower part of the screen. Used to revert the back button navigation action. Defaults to true.

    Declaration

    Swift

    public func showForwardActionButton(_ showForwardActionButton: Bool) -> PDFView
  • Adds text labels representing the destination name to the back and forward buttons. Defaults to true on iPad and false otherwise.

    Declaration

    Swift

    public func showBackForwardActionButtonLabels(_ showBackForwardActionButtonLabels: Bool) -> PDFView
  • Sets the thumbnail bar mode. Defaults to .floatingScrubberBar.

    Declaration

    Swift

    public func thumbnailBarMode(_ thumbnailBarMode: ThumbnailBarMode) -> PDFView
  • Controls the placement of the scrubber bar. Defaults to .horizontal.

    @note Customizing scrubberBarType is supported only when thumbnailBarMode is .scrubberBar. Otherwise, setting this property to any value other than .horizontal won’t have any effect.

    Declaration

    Swift

    public func scrubberBarType(_ scrubberBarType: ScrubberBarType) -> PDFView
  • If true, asks the user to specify a custom annotation username (“author”) when first creating a new annotation

    This is triggered by the AnnotationStateManager changing its state.

    A default name will already be suggested based on the device name. You can change the default username by setting -[PSPDFDocument defaultAnnotationUsername]. Defaults to true.

    Declaration

    Swift

    public func shouldAskForAnnotationUsername(_ shouldAskForAnnotationUsername: Bool) -> PDFView
  • Whether PSPDFKit should save automatically in response to certain UI triggers, such as the app entering the background or the view disappearing.

    Defaults to true because users generally expect saving to be automatic on iOS. The exact save triggers may change between PSPDFKit versions. See https:pspdfkit.com/guides/ios/current/annotations/annotation-and-bookmark-saving-triggers/ for details.

    Set this property to false if you want to save with different triggers, such as when the user manually requests this. You can save using the Document method save(options:) or save(options:completion:).

    To fully disable a Document from saving, set its annotationSaveMode to .disabled. See https:pspdfkit.com/guides/ios/current/annotations/annotation-saving-mechanism/ for details.

    Implement PDFDocumentDelegate to be notified when automatic saving succeeds or fails.

    Declaration

    Swift

    public func autosaveEnabled(_ autosaveEnabled: Bool) -> PDFView
  • Set this to true to allow this controller to access the parent navigationBar/navigationController to add custom buttons. Has no effect if there’s no parentViewController. Defaults to false.

    Declaration

    Swift

    public func useParentNavigationBar(_ useParentNavigationBar: Bool) -> PDFView