Other Functions

The following functions are available globally.

  • Checks that the requested interface orientation is supported by both view controller and application.

    Declaration

    Objective-C

    extern UIInterfaceOrientation
    PSPDFSafePreferredInterfaceOrientation(UIInterfaceOrientation requested,
                                           UIInterfaceOrientationMask supported,
                                           UIWindow *_Nullable window)

    Swift

    func PSPDFSafePreferredInterfaceOrientation(_ requested: UIInterfaceOrientation, _ supported: UIInterfaceOrientationMask, _ window: UIWindow?) -> UIInterfaceOrientation

    Parameters

    requested

    The requested preferred interface orientation.

    supported

    Value from view controller’s supportedInterfaceOrientations.

    window

    Window which hosts the view controller.

    Return Value

    Requested orientation if it’s supported by both view controller and application, otherwise falls back to current orientation.

  • A helper to quickly determine if a coordinated data provider provides conflict resolution at a given moment.

    Declaration

    Objective-C

    static inline BOOL PSPDFConflictResolutionAvailableForDataProvider(
        id<PSPDFCoordinatedFileDataProviding> _Nonnull dataProvider)

    Swift

    func PSPDFConflictResolutionAvailableForDataProvider(_ dataProvider: PSPDFCoordinatedFileDataProviding) -> Bool

    Parameters

    dataProvider

    The data provider to check.

    Return Value

    YES if conflict resolution APIs are implemented and conflict resolution is currently possible. NO in all other cases.

  • Undocumented

    Declaration

    Objective-C

    PSPDF_EXPORT UIApplication *PSPDFSharedApplication(void)

    Swift

    func PSPDFSharedApplication() -> UIApplication!
  • Searches the responder chain for the closest system bar (toolbar/navigation bar).

    Declaration

    Objective-C

    extern UIView<PSPDFSystemBar> *_Nullable PSPDFSystemBarForResponder(
        UIResponder *_Nonnull responder)

    Swift

    func PSPDFSystemBarForResponder(_ responder: UIResponder) -> (UIView & PSPDFSystemBar)?
  • Converts an array of glyphs to a string.

    Declaration

    Objective-C

    extern NSString *_Nonnull PSPDFStringFromGlyphs(
        NSArray<PSPDFGlyph *> *_Nullable glyphs)

    Swift

    func PSPDFStringFromGlyphs(_ glyphs: [PSPDFGlyph]?) -> String
  • Returns the bounding box that includes all glyphs.

    Declaration

    Objective-C

    extern CGRect
    PSPDFBoundingBoxFromGlyphs(NSArray<PSPDFGlyph *> *_Nullable glyphs)

    Swift

    func PSPDFBoundingBoxFromGlyphs(_ glyphs: [PSPDFGlyph]?) -> CGRect

    Return Value

    Rect encompassing all glyphs or CGRectZero if glyphs is empty.

  • Global helper to convert glyphs to rects.

    Declaration

    Objective-C

    extern NSArray<NSValue *> *_Nonnull PSPDFRectsFromGlyphs(
        NSArray<PSPDFGlyph *> *_Nullable glyphs, CGRect *_Nonnull boundingBox)

    Swift

    func PSPDFRectsFromGlyphs(_ glyphs: [PSPDFGlyph]?, _ boundingBox: UnsafeMutablePointer<CGRect>) -> [NSValue]
  • Returns an NSRange representing the glyphs in glyphs, assuming they are in ascending order of their indexOnPage. If glyphs is not sorted, this method this method will return a wrong result. PSPDFInvalidGlyphRange is returned an empty array, or if the last glyph has an indexOnPage that is prior to the first one.

    Declaration

    Objective-C

    extern NSRange PSPDFRangeFromGlyphs(NSArray<PSPDFGlyph *> *_Nonnull glyphs)

    Swift

    func PSPDFRangeFromGlyphs(_ glyphs: [PSPDFGlyph]) -> NSRange
  • Calculates the bounding box from lines.

    Declaration

    Objective-C

    extern CGRect PSPDFBoundingBoxFromLines(NSArray *_Nonnull lines,
                                            CGFloat lineWidth)

    Swift

    func PSPDFBoundingBoxFromLines(_ lines: [Any], _ lineWidth: CGFloat) -> CGRect

    Parameters

    lines

    Either an NSArray <PSPDFPointArray *> or NSArray <NSArray <NSValue *> *>.

  • Will convert view lines to PDF lines (operates on every point)

    Declaration

    Objective-C

    extern NSArray<NSArray<NSValue *> *> *_Nonnull PSPDFConvertViewLinesToPDFLines(
        NSArray<NSArray<NSValue *> *> *_Nonnull lines,
        PSPDFPageInfo *_Nonnull pageInfo, CGRect viewBounds)

    Swift

    func PSPDFConvertViewLinesToPDFLines(_ lines: [[NSValue]], _ pageInfo: PSPDFPageInfo, _ viewBounds: CGRect) -> [[NSValue]]
  • Converts a single line of boxed PSPDFDrawingPoints.

    Declaration

    Objective-C

    extern NSArray<NSValue *> *_Nonnull PSPDFConvertViewLineToPDFLines(
        NSArray<NSValue *> *_Nonnull line, PSPDFPageInfo *_Nonnull pageInfo,
        CGRect bounds)

    Swift

    func PSPDFConvertViewLineToPDFLines(_ line: [NSValue], _ pageInfo: PSPDFPageInfo, _ bounds: CGRect) -> [NSValue]
  • Will convert PDF lines to view lines (arrays of PSPDFDrawingPoints) (operates on every point)

    Declaration

    Objective-C

    extern NSArray<NSArray<NSValue *> *> *_Nonnull PSPDFConvertPDFLinesToViewLines(
        NSArray<NSArray<NSValue *> *> *_Nonnull lines,
        PSPDFPageInfo *_Nonnull pageInfo, CGRect viewBounds)

    Swift

    func PSPDFConvertPDFLinesToViewLines(_ lines: [[NSValue]], _ pageInfo: PSPDFPageInfo, _ viewBounds: CGRect) -> [[NSValue]]
  • Localizes strings. Will first look up the string in the PSPDFKit.bundle

    Declaration

    Objective-C

    extern NSString *_Nonnull PSPDFLocalize(NSString *_Nullable stringToken)

    Swift

    func PSPDFLocalize(_ stringToken: String?) -> String
  • Localizes strings with a list of arguments to substitute into stringToken.

    Declaration

    Objective-C

    extern NSString *_Nonnull PSPDFLocalizeFormatted(NSString *_Nonnull stringToken,
                                                     ...)
  • Sets a custom dictionary that contains dictionaries with language locales. Will override localization found in the bundle, if a value is found. Falls back to en if localization key is not found in dictionary. Set on the main thread.

    Declaration

    Objective-C

    extern void PSPDFSetLocalizationDictionary(
        NSDictionary<NSString *, NSDictionary<NSString *, NSString *> *>
            *_Nullable localizationDict)

    Swift

    func PSPDFSetLocalizationDictionary(_ localizationDict: [String : [String : String]]?)
  • Register a custom block that handles translation. If this block is NULL or returns nil, the PSPDFKit.bundle + localizationDict will be used.

    Declaration

    Objective-C

    extern void PSPDFSetLocalizationBlock(
        NSString *_Nullable (^_Nonnull localizationBlock)(NSString *_Nullable))

    Swift

    func PSPDFSetLocalizationBlock(_ localizationBlock: @escaping (String?) -> String?)
  • Convert a view point to the normalized PDF coordinate space. bounds is from the view. (usually PSPDFPageView.bounds)

    Declaration

    Objective-C

    extern CGPoint PSPDFConvertViewPointToPDFPoint(CGPoint viewPoint,
                                                   PSPDFPageInfo *_Nonnull pageInfo,
                                                   CGRect viewBounds)

    Swift

    func PSPDFConvertViewPointToPDFPoint(_ viewPoint: CGPoint, _ pageInfo: PSPDFPageInfo, _ viewBounds: CGRect) -> CGPoint
  • Converts a point in a normalized PDF coordinate space to the view coordinate space.

    Declaration

    Objective-C

    extern CGPoint PSPDFConvertPDFPointToViewPoint(CGPoint pdfPoint,
                                                   PSPDFPageInfo *_Nonnull pageInfo,
                                                   CGRect viewBounds)

    Swift

    func PSPDFConvertPDFPointToViewPoint(_ pdfPoint: CGPoint, _ pageInfo: PSPDFPageInfo, _ viewBounds: CGRect) -> CGPoint
  • Converts a rectangle from a normalized PDF coordinate space to the view coordinate space.

    Note

    Important: This is not a general purpose conversion function from PDF page to UIKit coordinates! If the pdfRect has negative width or height, the results will be unexpected.

    Declaration

    Objective-C

    extern CGRect PSPDFConvertPDFRectToViewRect(CGRect pdfRect,
                                                PSPDFPageInfo *_Nonnull pageInfo,
                                                CGRect viewBounds)

    Swift

    func PSPDFConvertPDFRectToViewRect(_ pdfRect: CGRect, _ pageInfo: PSPDFPageInfo, _ viewBounds: CGRect) -> CGRect
  • Converts a rectangle in a view coordinate space to the normalized PDF coordinate space.

    Note

    Important: This is not a general purpose conversion function from UIKit to PDF page coordinates! If the viewRect has negative width or height, the results will be unexpected.

    Declaration

    Objective-C

    extern CGRect PSPDFConvertViewRectToPDFRect(CGRect viewRect,
                                                PSPDFPageInfo *_Nonnull pageInfo,
                                                CGRect viewBounds)

    Swift

    func PSPDFConvertViewRectToPDFRect(_ viewRect: CGRect, _ pageInfo: PSPDFPageInfo, _ viewBounds: CGRect) -> CGRect
  • Performs a block and groups all observed changes into one event, if the undo controller is available.

    Declaration

    Objective-C

    extern void
    PSPDFPerformBlockAsGroup(PSPDFUndoController *_Nullable undoController,
                             dispatch_block_t _Nonnull block,
                             NSString *_Nullable name)

    Swift

    func PSPDFPerformBlockAsGroup(_ undoController: PSPDFUndoController?, _ block: () -> Void, _ name: String?)
  • Performs a block and ignores all observed changes, if the undo controller is available.

    Declaration

    Objective-C

    extern void
    PSPDFPerformBlockWithoutUndo(PSPDFUndoController *_Nullable undoController,
                                 dispatch_block_t _Nonnull block)

    Swift

    func PSPDFPerformBlockWithoutUndo(_ undoController: PSPDFUndoController?, _ block: () -> Void)
  • Helper method that will dig into popovers, navigation controllers, container view controllers or other controller view hierarchies and dig out the requested class if found.

    Declaration

    Objective-C

    extern id _Nullable PSPDFChildViewControllerForClass(
        UIViewController *_Nullable controller, Class _Nonnull controllerClass)

    Swift

    func PSPDFChildViewControllerForClass(_ controller: UIViewController?, _ controllerClass: AnyClass) -> Any?