Expand description
§pdfkit-rs
Safe Rust bindings for Apple’s PDFKit framework on macOS. The published Cargo package is pdfkit-rs; the Rust library target is pdfkit.
Status: v0.2.2 closes the remaining public PDFKit audit gaps with
PdfActionResetForm, typed annotation key/subtype/icon constants, selection granularity and page-image initialization options,PdfViewDelegate,PdfPageOverlayViewProvider, and 100% coverage of the non-deprecated top-level SDK declarations counted byCOVERAGE_AUDIT.md.
§Highlights
PdfDocumentfor loading, creating, mutating, saving, attaching delegates, option-driven writes, and granularity-aware selectionsPdfPagefor bounds, text, character geometry, annotations, selections, and image-backed page creationPdfAction,PdfActionResetForm,PdfActionUrl,PdfActionGoTo,PdfActionNamed, andPdfActionRemoteGoTofor abstract and concrete action inspection/editingPdfAnnotation,PdfOutline,PdfBorder,PdfDestination, and typed annotation key/subtype/icon wrappers for navigation and form metadataPdfDocumentDelegate,PdfViewDelegate,PdfPageOverlayViewProvider,PdfDocumentWriteOptions, and structuredPDFDocument/PDFView/PDFThumbnailViewnotification namesPdfAppearanceCharacteristics,PdfPrintScalingMode,PdfTextAnnotationIconType,PdfThumbnailLayoutMode,PdfWidgetCellState, andPdfAccessibilityNode::public_api_available()
§Quick start
use pdfkit::prelude::*;
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let document = PdfDocument::from_url("document.pdf")?;
let page = document
.page(0)
.ok_or_else(|| std::io::Error::other("missing first page"))?;
let destination = PdfDestination::new(&page, PdfPoint { x: 36.0, y: 72.0 })?;
let action = PdfActionGoTo::new(&destination)?;
println!("pages={}", document.page_count());
println!("first page text={:?}", page.string());
println!("goto action type={:?}", action.action_type());
Ok(())
}§Surface overview
§Documents, pages, and selections
PdfDocument::new,from_url,from_bytes,write_to_url,write_to_url_with_optionsPdfDocument::insert_page,remove_page,exchange_pages,set_outline_root,set_delegate,unlockPdfDocument::selection_for_entire_document,selection_from_page_points,selection_from_page_points_with_granularity,selection_from_page_charactersPdfPage::new,from_image_data,bounds,set_bounds,rotation,set_rotationPdfPageImageInitializationOptions::{new, with_media_box, with_rotation, with_upscale_if_smaller, with_compression_quality}PdfPage::selection_for_range,selection_for_rect,selection_for_word_at_point,selection_for_line_at_pointPdfSelection::new,text_range,selections_by_line,add_selection
§Actions, outlines, and annotations
PdfAction::action_type,as_url,as_goto,as_named,as_remote_goto,as_reset_formPdfActionResetForm::new,fields,set_fields,clear_fields,fields_included_are_cleared,set_fields_included_are_cleared,action_typePdfActionUrl::new,url,set_url,action_typePdfActionGoTo::new,destination,set_destination,action_typePdfActionNamed::new,name,set_name,action_typePdfActionRemoteGoTo::new,page_index,set_page_index,point,set_point,url,set_url,action_typePdfOutline::new,insert_child,set_label,set_destination,action,set_action,clear_actionPdfAnnotation::new,new_with_subtype,info,set_contents,set_border,action,set_action,clear_actionPdfAnnotationKey,PdfAnnotationHighlightingMode,PdfAnnotationLineEndingStyle,PdfAnnotationSubtype,PdfAnnotationTextIconName,PdfAnnotationWidgetSubtypePdfBorder::new,info,set_style,set_line_width,set_dash_patternPdfDestination::new,info,page,set_zoom,compare
§Delegates, notifications, and utilities
PdfDocumentDelegate,PdfDocumentDelegateHandle,PdfViewDelegate,PdfViewDelegateHandlePdfPageOverlayViewProvider,PdfPageOverlayViewProviderHandle,PdfPageOverlayViewPdfDocumentWriteOptions::{with_owner_password, with_user_password, with_access_permissions, with_burn_in_annotations, with_save_text_from_ocr, with_save_images_as_jpeg, with_optimize_images_for_screen}PdfDocumentNotification,PdfDocumentNotificationUserInfoKey,PdfViewNotification,PdfThumbnailViewNotificationPdfActionNamedName,PdfLineStyle,PdfMarkupType,PdfPrintScalingMode,PdfSelectionGranularity,PdfTextAnnotationIconType,PdfThumbnailLayoutMode,PdfWidgetCellState
§View state, widget appearance, and accessibility status
PdfView::new,set_document,set_delegate,set_page_overlay_view_provider,set_display_mode,set_display_direction,set_display_boxPdfView::set_current_selection,go_to_page,go_to_destination,visible_pages,area_of_interest_for_pointPdfThumbnailView::new,set_pdf_view,set_thumbnail_size,set_maximum_number_of_columnsPdfAppearanceCharacteristics::new,set_control_type,set_caption,set_background_color,infoPdfAreaOfInterest,PdfDestination::UNSPECIFIED_VALUE,PdfAccessibilityNode::public_api_available,PdfAccessibilityNode::availability_note
§Examples
The crate now ships smoke examples covering the core logical areas:
01_document_smoke02_page_basics03_annotation_link04_outline_tree05_selection_ranges06_view_state07_thumbnail_view_state08_action_url09_action_goto10_border_style11_destination_compare12_appearance_characteristics13_accessibility_node_status14_action_named_remote_goto15_document_delegate_write_options
Run one example:
cargo run --example 06_view_stateRun all examples:
for ex in examples/*.rs; do cargo run --example "$(basename "$ex" .rs)"; done§Coverage audit
See COVERAGE.md for the v0.2.2 header audit and COVERAGE_AUDIT.md for the symbol-level 100% audit report.
§License
Licensed under either of Apache-2.0 or MIT at your option.
§API Documentation
Safe Rust bindings for Apple’s PDFKit framework on macOS.
Modules§
- prelude
- Re-exports the primary PDFKit wrapper types.
Structs§
- PdfAccessibility
Node - Wraps
PDFAccessibilityNode. - PdfAction
- Wraps
PDFAction. - PdfAction
GoTo - Wraps
PDFActionGoTo. - PdfAction
Named - Wraps
PDFActionNamed. - PdfAction
Remote GoTo - Wraps
PDFActionRemoteGoTo. - PdfAction
Reset Form - Wraps
PDFActionResetForm. - PdfAction
Url - Wraps
PDFActionURL. - PdfAnnotation
- Wraps
PDFAnnotation. - PdfAnnotation
Info - Snapshot of
PDFAnnotationstate. - PdfAppearance
Characteristics - Wraps
PDFAppearanceCharacteristics. - PdfAppearance
Characteristics Info - Snapshot of
PDFAppearanceCharacteristicsstate. - PdfArea
OfInterest - Wraps
PDFView area-of-interest. - PdfBorder
- Wraps
PDFBorder. - PdfBorder
Info - Snapshot of
PDFBorderstate. - PdfColor
- Wraps RGBA color values used by PDFKit.
- PdfDestination
- Wraps
PDFDestination. - PdfDestination
Info - Snapshot of
PDFDestinationstate. - PdfDocument
- Wraps
PDFDocument. - PdfDocument
Attributes - Wraps
PDFDocumentAttributes. - PdfDocument
Delegate Handle - Wraps
PDFDocumentDelegateHandle. - PdfDocument
Info - Snapshot of
PDFDocumentstate. - PdfDocument
Write Options - Builder-style options for the corresponding
PDFDocumentWriteAPI. - PdfEdge
Insets - Wraps
NSEdgeInsetsvalues used byPDFView. - PdfKit
Error - Wraps
PDFKitError. - PdfOutline
- Wraps
PDFOutline. - PdfPage
- Wraps
PDFPage. - PdfPage
Image Initialization Options - Builder-style options for the corresponding
PDFPageImageInitializationAPI. - PdfPage
Overlay View - Wraps
PDFPageOverlayView. - PdfPage
Overlay View Provider Handle - Wraps
PDFPageOverlayViewProviderHandle. - PdfPoint
- Wraps
CGPointvalues used by PDFKit geometry APIs. - PdfRect
- Wraps
CGRectvalues used by PDFKit geometry APIs. - PdfSelection
- Wraps
PDFSelection. - PdfSize
- Wraps
CGSizevalues used by PDFKit geometry APIs. - PdfText
Range - Wraps text-range values returned by
PDFSelection. - PdfThumbnail
View - Wraps
PDFThumbnailView. - PdfThumbnail
View Info - Snapshot of
PDFThumbnailViewstate. - PdfView
- Wraps
PDFView. - PdfView
Delegate Handle - Wraps
PDFViewDelegateHandle. - PdfView
Info - Snapshot of
PDFViewstate.
Enums§
- Display
Box - Wraps
PDFDisplayBoxvalues. - PdfAction
Named Name - Wraps
PDFActionNamedNamevalues. - PdfAnnotation
Highlighting Mode - Wraps
PdfAnnotationHighlightingModevalues. - PdfAnnotation
Key - Wraps
PdfAnnotationKeyvalues. - PdfAnnotation
Line Ending Style - Wraps
PdfAnnotationLineEndingStylevalues. - PdfAnnotation
Subtype - Wraps
PdfAnnotationSubtypevalues. - PdfAnnotation
Text Icon Name - Wraps
PdfAnnotationTextIconNamevalues. - PdfAnnotation
Widget Subtype - Wraps
PdfAnnotationWidgetSubtypevalues. - PdfBorder
Style - Wraps
PDFBorderStylevalues. - PdfDisplay
Direction - Wraps
PDFDisplayDirectionvalues. - PdfDisplay
Mode - Wraps
PDFDisplayModevalues. - PdfDocument
Notification - Wraps
PDFDocument notificationconstants. - PdfDocument
Notification User Info Key - Wraps
PDFDocument notification user-info keyconstants. - PdfDocument
Permissions - Wraps
PDFDocumentPermissionsvalues. - PdfInterpolation
Quality - Wraps
PDFInterpolationQualityvalues. - PdfLine
Style - Wraps
PDFLineStylevalues. - PdfMarkup
Type - Wraps
PDFMarkupTypevalues. - PdfPrint
Scaling Mode - Wraps
PDFPrintScalingModevalues. - PdfSelection
Granularity - Wraps
PDFSelectionGranularityvalues. - PdfText
Annotation Icon Type - Wraps
PDFTextAnnotationIconTypevalues. - PdfThumbnail
Layout Mode - Wraps
PDFThumbnailLayoutModevalues. - PdfThumbnail
View Notification - Wraps
PDFThumbnailView notificationconstants. - PdfView
Notification - Wraps
PDFView notificationconstants. - PdfWidget
Cell State - Wraps
PDFWidgetCellStatevalues. - PdfWidget
Control Type - Wraps
PDFWidgetControlTypevalues.
Traits§
- PdfAction
Like - Mirrors the
PDFActionLikecallback surface. - PdfDocument
Delegate - Mirrors the
PDFDocumentDelegatecallback surface. - PdfPage
Overlay View Provider - Mirrors the
PDFPageOverlayViewProvidercallback surface. - PdfView
Delegate - Mirrors the
PDFViewDelegatecallback surface.
Type Aliases§
- Result
- Result alias used by the PDFKit wrappers.