Skip to content

Latest commit

 

History

History
77 lines (69 loc) · 17 KB

PDFKit.md

File metadata and controls

77 lines (69 loc) · 17 KB

PDFKit

Symbols: 100.0% of Apple's iOS API (575 of 575, exact) · Rows: 25: 19 ✅ 6 🟡 · iOS: 11.0+

Area: Graphics & text · Apple: PDFKit · Issues: area:graphics

How isim implements it

  • Approach: adapted. isim's own Objective-C implementation (isim/frameworks/PDFKit) is built on Core Graphics' PDF object model (CoreGraphics: isim's parser reads the pages, boxes, outline, labels, info and encryption). poppler-glib renders the pages through CGContextDrawPDFPage and extracts their text. A document is an array of pages; each page draws from the document it came from, from an image, or nothing (a blank page).
  • Selections and find (issue #358): a PDFSelection is a set of character indexes per page, over each page's text and character rectangles (poppler's); lines are the text between line breaks, words runs of letters and digits. Finding searches each page's string (NSString compare options); beginFindString searches one page per turn of the main queue, posting the find notifications and calling the delegate.
  • Annotations (issue #358): read from each page's /Annots when first needed (widgets inherit their field's attributes), with their dictionary's values as properties (annotationKeyValues); made, changed and removed. Like Apple's, CGContextDrawPDFPage draws pages without their annotations; PDFKit draws them from their properties (highlights, underlines and strike-outs over their quadrilaterals, ink, squares, circles, lines with their endings, notes, free text, stamps, form fields with their values), not from their appearance streams. Writing adds each annotation's dictionary to the written page (Core Graphics rewrites cairo's file with them), or draws them into the pages with PDFDocumentBurnInAnnotationsOption.
  • Writing: every page is redrawn into a CGPDFContext (cairo's PDF surface), so vector content stays vector. A rotated page is written turned, with rotation 0, and its crop box becomes the media box. The outline (with page destinations) and the title, author, subject, creator and keywords are written too, and every annotation (links included).
  • Views: PDFView is a UIScrollView of page views that isim lays out at the scale factor; every page view redraws at its size, so pages stay sharp at every zoom. The behaviour follows iOS: continuous single pages, fitted to the width with autoScales, white pages with shadows on a gray background, pinch to zoom, a double tap to zoom in or back to fit, a tap on an annotation that performs its action (a link followed, a check box or radio button toggled, .PDFViewAnnotationHit posted) and a long press that selects a word. The current selection is drawn in blue and the highlighted selections in yellow (or their color); the find interaction searches the document. PDFThumbnailView is a strip of page thumbnails that outlines the current page and goes to a page when its thumbnail is tapped. Every interaction is a script command: tap, tapid pdfthumbnail-N, pinch and drag (docs/SCRIPTING.md); page views have the ids pdfpage-N.
  • Objective-C / C interface: Apple's headers in isim/sdk-src/Frameworks/PDFKit; Swift imports them.
  • Versus Apple's Simulator: documents read, edit and write the same way. Differences: the written file is a new PDF rather than an incremental save of the original, and it is never encrypted; annotations are drawn from their properties rather than their appearance streams, and their appearance streams are not written; text fields are not edited in place.

API

API / feature Status iOS Notes
PDFDocument (init(), init(url:), init(data:), documentURL, documentRef, majorVersion / minorVersion, pageCount, page(at:), index(for:), insert(_:at:), removePage(at:), exchangePage(at:withPageAt:), pageClass, string, delegate with classForPage) ✅ ≤17 adapted: pages made when first needed, with the delegate's page class; string joins the pages' text with newlines; tested (PDFKitTest, HelloPDF)
PDFDocument encryption (isEncrypted, isLocked, unlock(withPassword:), permissionsStatus, accessPermissions, allowsPrinting, allowsCopying, allowsDocumentChanges, allowsDocumentAssembly, allowsContentAccessibility, allowsCommenting, allowsFormFieldEntry, .PDFDocumentDidUnlock, documentDidUnlock(_:)) ✅ ≤17 adapted: RC4, AES-128 and AES-256 with user and owner passwords, from Core Graphics' standard security handler; an empty user password unlocks by itself; tested (PDFKitTest)
PDFDocument.documentAttributes (PDFDocumentAttribute) ✅ ≤17 adapted: title, author, subject, creator, producer and keywords (an array) as strings; creation and modification dates as Date; tested (PDFKitTest, HelloPDF)
PDFDocument writing (dataRepresentation(), dataRepresentation(options:), write(to:), write(to:withOptions:), write(toFile:), write(toFile:withOptions:), .PDFDocumentDidBeginWrite / .PDFDocumentDidEndWrite) 🟡 ≤17 adapted: the pages redrawn into a new PDF with the outline and the attributes; tested (PDFKitTest, HelloPDF). Missing: the PDFDocumentWriteOption keys (passwords, access permissions, burn-in, OCR text, JPEG images) are accepted but ignored, so the file is written unencrypted; producer and dates are cairo's own; link annotations are not written
PDFPage (init(), init(image:), init(image:options:), document, pageRef, label, bounds(for:), setBounds(_:for:), rotation, displaysAnnotations, dataRepresentation, PDFDisplayBox, PDFPageImageInitializationOption) ✅ ≤17 adapted: a blank page is US Letter; an image page is aspect-fitted into its media box (upscaled only with the option; compression quality ignored); bleed, trim and art boxes default to the crop box; labels from /PageLabels (decimal, roman, letters, prefixes, starts), otherwise the page number; tested (PDFKitTest, HelloPDF)
PDFPage drawing (draw(with:to:), transform(_:for:), transform(for:), thumbnail(of:for:)) ✅ ≤17 adapted: the box's origin moved to 0 and turned by the rotation; thumbnails on white, fitted to the size; tested (PDFKitTest pixels, HelloPDF)
PDFPage text (string, attributedString, numberOfCharacters, characterBounds(at:), characterIndex(at:)) 🟡 ≤17 adapted: poppler's text and per-character rectangles, mapped to page space on rotated pages; tested (PDFKitTest, HelloPDF). Missing: attributedString carries no fonts or colours
PDFOutline (init(), document, parent, numberOfChildren, index, child(at:), insertChild(_:at:), removeFromParent(), label, isOpen, destination, action) 🟡 ≤17 adapted: read from /Outlines (destinations explicit, named in /Dests or the /Names tree, or behind a GoTo action), edited, written back; the action read from /A (issue #358); tested (PDFKitTest, HelloPDF). Missing: written items keep only their destination's page (not their action)
PDFDestination (init(page:at:), page, point, zoom, compare(_:), kPDFDestinationUnspecifiedValue) ✅ ≤17 adapted: XYZ, Fit, FitH/V/B and FitR destinations; unspecified coordinates and zoom are kPDFDestinationUnspecifiedValue; compare orders by page, then top to bottom, then left to right; tested (PDFKitTest)
PDFSelection (init(document:), pages, string, attributedString, color, bounds(for:), numberOfTextRanges(on:), range(at:on:), selectionsByLine(), add(_:), extend(atEnd:), extend(atStart:), extendForLineBoundaries(), draw(for:active:), draw(for:with:active:)), PDFSelectionGranularity ✅ ≤17 adapted: character indexes per page over the page's text (poppler); disjoint ranges and pages joined by line breaks in string; attributedString is plain; drawing fills the characters' rectangles (the active selection in blue). Tested (PDFKitTest: test_pdfkit)
PDFPage selections and annotations (selection(for:) a range or a rect, selection(from:to:), selectionForWord(at:), selectionForLine(at:), annotations, addAnnotation(_:), removeAnnotation(_:), annotation(at:)) ✅ ≤17 adapted: a point selects the character under it, else the nearest one; a rect selects the characters whose centers it holds; annotations read from /Annots when first needed (the delegate's classForAnnotationType(_:)); drawing draws them after the content when displaysAnnotations is set. Tested (PDFKitTest, HelloPDF)
PDFDocument find and selections (findString(_:withOptions:), findString(_:fromSelection:withOptions:), beginFindString(_:withOptions:), beginFindStrings(_:withOptions:), cancelFindString(), isFinding, the find notifications and PDFDocumentFoundSelectionKey / PDFDocumentPageIndexKey, the delegate's find methods and didMatchString(_:), selectionForEntireDocument, selection(from:at:to:at:) (with PDFSelectionGranularity, iOS 18), selection(from:atCharacterIndex:to:atCharacterIndex:), outlineItem(for:)) ✅ ≤17 adapted: each page's string searched with NSString's compare options; asynchronous finds run one page per turn of the main queue; findString(_:fromSelection:) does not wrap around; outlineItem(for:) is the last item whose destination is at or before the selection. Tested (PDFKitTest)
PDFAnnotation (init(bounds:forType:withProperties:), page, type, bounds, shouldDisplay, shouldPrint, userName, modificationDate, color, contents, popup, border, action, hasAppearanceStream, isHighlighted, draw(with:in:), setValue(_:forAnnotationKey:), setBoolean, setRect, annotationKeyValues, value(forAnnotationKey:), removeValue(forAnnotationKey:), NSCoding), PDFAnnotationKey, PDFAnnotationSubtype ✅ ≤17 adapted: the properties are the dictionary's values (colors as UIColor, the border as PDFBorder, actions as PDFAction); drawn from its properties, not its appearance stream; written as a dictionary of its properties (no appearance stream). NSCoding keeps the type, bounds, contents and labels. Tested (PDFKitTest, HelloPDF)
PDFAnnotation utilities (font, fontColor, interiorColor, alignment, startPoint / endPoint, startLineStyle / endLineStyle, lineStyle(fromName:), name(for:), iconType, quadrilateralPoints, markupType, paths, add(_:), remove(_:), isOpen, destination, url, stampName, caption, backgroundColor), PDFLineStyle, PDFTextAnnotationIconType, PDFMarkupType, PDFAnnotationLineEndingStyle, PDFAnnotationTextIconType, PDFAnnotationHighlightingMode ✅ ≤17 adapted: the font and its color from /DA; points, quadrilaterals and paths relative to the bounds origin; markup drawn over the quadrilaterals (a highlight multiplied, an underline, a strike-out), ink with round caps, notes as a note icon, stamps as a framed name. Tested (PDFKitTest, HelloPDF)
Form fields (widgetFieldType, widgetControlType, isMultiline, isPasswordField, hasComb, maximumLength, widgetStringValue, widgetDefaultStringValue, allowsToggleToOff, radiosInUnison, isReadOnly, isListChoice, choices, values, buttonWidgetState, buttonWidgetStateString, fieldName, isActivatableTextField), PDFAnnotationWidgetSubtype, PDFWidgetControlType, PDFWidgetCellState, PDFAppearanceCharacteristics, PDFAppearanceCharacteristicsKey 🟡 ≤17 adapted: a widget inherits /FT, /T (the full name), /V, /Ff, /Opt, /DA from its parent fields; drawn with its background, border and value (a check mark, a radio dot, a caption, the text); a tap in a PDFView toggles check boxes and radio buttons. Missing: text fields are not edited in place, choice fields have no picker. Tested (PDFKitTest)
PDFBorder (style, lineWidth, dashPattern, borderKeyValues, draw(in:), NSCoding), PDFBorderStyle, PDFBorderKey ✅ ≤17 adapted: read from /BS or /Border; written as both. Tested (PDFKitTest)
PDFAction (type), PDFActionGoTo, PDFActionURL, PDFActionNamed (PDFActionNamedName), PDFActionRemoteGoTo, PDFActionResetForm ✅ ≤17 adapted: read from link annotations and outline items (/A: GoTo, URI, Named, GoToR, ResetForm), written with link annotations; PDFView.perform(_:) goes to destinations, opens URLs (the delegate first), performs the named actions, hands remote go-tos to pdfViewOpenPDF(_:forRemoteGoToAction:) and resets form fields. Tested (PDFKitTest)
Writing annotations (dataRepresentation(), write(to:), PDFDocumentBurnInAnnotationsOption) ✅ 16.0 adapted: each annotation's dictionary added to its written page (Core Graphics rewrites the file cairo made, adding the objects to the pages' /Annots); with the burn-in option they are drawn into the pages instead. Tested (PDFKitTest: written and read back, burnt in)
PDFView (document, currentPage, currentDestination, visiblePages, go(to:) a page / a destination, go(to:on:), goToFirstPage(_:) / goToLastPage(_:) / goToNextPage(_:) / goToPreviousPage(_:), goBack(_:) / goForward(_:) and their canGo…, documentView, layoutDocumentView(), annotationsChanged(on:), rowSize(for:)) ✅ ≤17 adapted: history of the places gone to; the current page is the most visible one; tested (PDFKitTest, HelloPDF)
PDFView display (displayMode, displayDirection, displaysPageBreaks, pageBreakMargins, displayBox, displaysAsBook, displaysRTL, backgroundColor, pageShadowsEnabled, interpolationQuality, shouldAntiAlias, usePageViewController(_:withViewOptions:), isUsingPageViewController, pageOverlayViewProvider, isInMarkupMode) ✅ ≤17 adapted: single page or continuous, one or two up, vertical or horizontal; a page view controller is a horizontally paged scroll view (no page curl); overlay views sit over their page views; markup mode turns off PDFView's own gestures; tested (PDFKitTest, HelloPDF)
PDFView scale (scaleFactor, minScaleFactor, maxScaleFactor, autoScales, scaleFactorForSizeToFit, zoomIn(_:), zoomOut(_:), canZoomIn, canZoomOut, pinch, double tap) ✅ ≤17 adapted: zooming keeps the point under the fingers (or the center) in place; zoom steps are √2; tested (PDFKitTest, HelloPDF pinch and double tap)
PDFView points and links (page(for:nearest:), convert(_:to:), convert(_:from:) for points and rects, areaOfInterest(for:), areaOfInterest(forMouse:), draw(_:to:), drawPagePost(_:to:), PDFViewDelegate: pdfViewWillClick(onLink:with:), pdfViewWillChangeScaleFactor(_:toScale:), pdfViewOpenPDF(_:forRemoteGoToAction:)) 🟡 ≤17 adapted: a tap on an annotation performs its action or goes to its destination (a URL through the delegate or UIApplication.open); areas of interest are page, text, annotation, link, control, text field, icon and popup; tested (PDFKitTest, HelloPDF). Missing: enableDataDetectors, greekingThreshold, allowsDragging and acceptsDraggedFiles are only stored; setCursorFor(_:) does nothing (no pointer cursors)
PDFView notifications (.PDFViewDocumentChanged, .PDFViewChangedHistory, .PDFViewPageChanged, .PDFViewScaleChanged, .PDFViewDisplayModeChanged, .PDFViewDisplayBoxChanged, .PDFViewVisiblePagesChanged, .PDFViewSelectionChanged, .PDFViewAnnotationHit, .PDFViewAnnotationWillHit, .PDFViewCopyPermission) ✅ ≤17 posted, and .PDFViewSelectionChanged, .PDFViewAnnotationWillHit / .PDFViewAnnotationHit ("PDFAnnotationHit" in the user info) and .PDFViewCopyPermission (issue #358); the print permission notification is defined, never posted; tested (PDFKitTest, HelloPDF)
PDFThumbnailView (pdfView, thumbnailSize, layoutMode, contentInset, backgroundColor, selectedPages, PDFThumbnailLayoutMode) 🟡 ≤17 adapted: thumbnails of the PDFView's document; the current page outlined; a tap goes to the page; tested (HelloPDF). Missing: allowsDragging, allowsMultipleSelection and maximumNumberOfColumns are only stored (one page selected, one row or column)
PDFView selection and find (currentSelection, setCurrentSelection(_:animate:), clearSelection(), selectAll(_:), scrollSelectionToVisible(_:), go(to:) a selection, highlightedSelections, isFindInteractionEnabled, findInteraction, perform(_:), copy(_:)) ✅ ≤17 adapted: the current selection drawn in blue, highlighted selections in yellow (or their color); a long press selects a word; the find interaction's session searches the document (Match Case and the word options), highlights every match and steps through them. Tested (PDFKitTest, HelloPDF: Find)

Not yet in isim

Nothing (or not measured yet).