Commit 71cfd8421d

71cfd8421de8b3d3c1fbdc9f394e56b267ec23e1

parent: ec0e3dfe3b

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-22 01:02 UTC

Scan documents into an attachment on iOS

More ▸ Attachments ▸ Scan Document… opens the document camera and saves
the pages as one PDF, linked at the caret like a taken photo.

Layout: unified · split

Sources/OrgstarMobile/DocumentScanner.swift added +52
@@ -0,0 +1,52 @@
1#if os(iOS)
2import SwiftUI
3import UIKit
4import VisionKit
5
6/// The document camera, for pages to attach; `scanned` gets them as one PDF, or nil when
7/// cancelled or failed.
8struct DocumentScanner: UIViewControllerRepresentable {
9 let scanned: (Data?) -> Void
10
11 static var isAvailable: Bool { VNDocumentCameraViewController.isSupported }
12
13 func makeUIViewController(context: Context) -> VNDocumentCameraViewController {
14 let scanner = VNDocumentCameraViewController()
15 scanner.delegate = context.coordinator
16 return scanner
17 }
18
19 func updateUIViewController(_ scanner: VNDocumentCameraViewController, context: Context) {}
20
21 func makeCoordinator() -> Coordinator { Coordinator(scanned: scanned) }
22
23 /// `pages` as a PDF, each page the size of its image in points.
24 static func pdf(_ pages: [UIImage]) -> Data {
25 UIGraphicsPDFRenderer(bounds: .zero).pdfData { context in
26 for page in pages {
27 let bounds = CGRect(origin: .zero, size: page.size)
28 context.beginPage(withBounds: bounds, pageInfo: [:])
29 page.draw(in: bounds)
30 }
31 }
32 }
33
34 final class Coordinator: NSObject, VNDocumentCameraViewControllerDelegate {
35 let scanned: (Data?) -> Void
36 init(scanned: @escaping (Data?) -> Void) { self.scanned = scanned }
37
38 func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
39 let pages = (0..<scan.pageCount).map(scan.imageOfPage(at:))
40 scanned(pages.isEmpty ? nil : DocumentScanner.pdf(pages))
41 }
42
43 func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
44 scanned(nil)
45 }
46
47 func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFailWithError error: Error) {
48 scanned(nil)
49 }
50 }
51}
52#endif
Sources/OrgstarMobile/EditorScreen.swift +11
@@ -66,6 +66,7 @@ struct EditorScreen: View {
6666 @State private var attaching: Attachments.Method?
6767 @State private var attachingPhotos = false
6868 @State private var takingPhoto = false
69 @State private var scanning = false
6970 @State private var photos: [PhotosPickerItem] = []
7071 /// A file shown in Quick Look.
7172 @State private var previewed: URL?
@@ -165,6 +166,9 @@ struct EditorScreen: View {
165166 if CameraPicker.isAvailable {
166167 Button("Take Photo…", systemImage: "camera") { takingPhoto = true }
167168 }
169 if DocumentScanner.isAvailable {
170 Button("Scan Document…", systemImage: "doc.viewfinder") { scanning = true }
171 }
168172 Button("Attach File from URL…", systemImage: "link.badge.plus") { attachActions.run("app.attach.url") }
169173 Button("New Attachment…", systemImage: "square.and.pencil") { attachActions.run("app.attach.new") }
170174 Button("Open Attachment…", systemImage: "paperclip") { attachActions.run("app.attach.open") }
@@ -310,6 +314,13 @@ struct EditorScreen: View {
310314 }
311315 .ignoresSafeArea()
312316 }
317 .fullScreenCover(isPresented: $scanning) {
318 DocumentScanner { data in
319 scanning = false
320 if let data { attachActions.yankImage(data, ext: "pdf", prefix: "scan") }
321 }
322 .ignoresSafeArea()
323 }
313324 .onChange(of: photos) { _, items in
314325 guard !items.isEmpty else { return }
315326 photos = []
docs/manual/guide/14-ios.org +1 −1
@@ -159,7 +159,7 @@ Incremental Search is in Commands, and on =C-s= and =C-r= with a hardware keyboa
159159
160160The org-timer commands are in Commands; a running timer shows above the text. See [[file:06-dates-and-clocking.org][Dates and clocking]].
161161
162More ▸ Attachments has the org-attach commands, Attach Photo or Video… and Take Photo…, which insert the photo's link at the caret; files shared to orgstar can be attached to an entry. Pasting an image and dropping files on the editor attach them and link them at the caret. Attachments are copied or moved: iOS doesn't let orgstar link a file from another app's storage, so the keys for attaching by hard link or symbolic link say "Attachments can't be linked on iPhone and iPad; Attach File… copies the file." See [[file:04-outlines.org][Outlines]] and [[file:09-links.org][Links]].
162More ▸ Attachments has the org-attach commands, Attach Photo or Video…, Take Photo… and Scan Document…, which insert the link to the photo, or to the scanned pages as one PDF, at the caret; files shared to orgstar can be attached to an entry. Pasting an image and dropping files on the editor attach them and link them at the caret. Attachments are copied or moved: iOS doesn't let orgstar link a file from another app's storage, so the keys for attaching by hard link or symbolic link say "Attachments can't be linked on iPhone and iPad; Attach File… copies the file." See [[file:04-outlines.org][Outlines]] and [[file:09-links.org][Links]].
163163
164164Archive Subtree in Commands (or =C-c C-x C-s= with a hardware keyboard) archives the entry at the caret where =org-archive-location= says, as on the Mac.
165165
ios/Orgstar/Info.plist +1 −1
@@ -53,7 +53,7 @@
5353 <key>NSCalendarsFullAccessUsageDescription</key>
5454 <string>The agenda shows your calendar events alongside your Org entries. orgstar changes your calendars only when you edit an event or add an entry to one.</string>
5555 <key>NSCameraUsageDescription</key>
56 <string>Photos you take from the editor are saved with your notes and linked where the caret is.</string>
56 <string>Photos you take and documents you scan from the editor are saved with your notes and linked where the caret is.</string>
5757 <key>NSFaceIDUsageDescription</key>
5858 <string>Face ID unlocks the passphrase of encrypted entries you asked orgstar to remember.</string>
5959 <key>NSRemindersFullAccessUsageDescription</key>
l10n/Localizable.xcstrings +34
@@ -26434,6 +26434,40 @@
2643426434 }
2643526435 }
2643626436 },
26437 "Scan Document…": {
26438 "localizations": {
26439 "de": {
26440 "stringUnit": {
26441 "state": "translated",
26442 "value": "Dokument scannen …"
26443 }
26444 },
26445 "es": {
26446 "stringUnit": {
26447 "state": "translated",
26448 "value": "Escanear documento…"
26449 }
26450 },
26451 "fr": {
26452 "stringUnit": {
26453 "state": "translated",
26454 "value": "Scanner un document…"
26455 }
26456 },
26457 "ja": {
26458 "stringUnit": {
26459 "state": "translated",
26460 "value": "書類をスキャン…"
26461 }
26462 },
26463 "pt-BR": {
26464 "stringUnit": {
26465 "state": "translated",
26466 "value": "Escanear Documento…"
26467 }
26468 }
26469 }
26470 },
2643726471 "Schedule": {
2643826472 "comment": "Command title",
2643926473 "localizations": {
scripts/build-ios-app.sh +1 −1
@@ -54,7 +54,7 @@ cat > "$app/Info.plist" <<PLIST
5454 <key>MinimumOSVersion</key>
5555 <string>26.0</string>
5656 <key>NSCameraUsageDescription</key>
57 <string>Photos you take from the editor are saved with your notes and linked where the caret is.</string>
57 <string>Photos you take and documents you scan from the editor are saved with your notes and linked where the caret is.</string>
5858 <key>NSFaceIDUsageDescription</key>
5959 <string>Face ID unlocks the passphrase of encrypted entries you asked orgstar to remember.</string>
6060 <key>NSCalendarsFullAccessUsageDescription</key>