Skip to content

Commit 6955338

Browse files
committed
save file to device.
1 parent fdb12ed commit 6955338

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

DocScan/Storyboards/Base.lproj/Main.storyboard

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ save any of your data on servers.</string>
164164
<!--DocScan-->
165165
<scene sceneID="c6O-n8-uKb">
166166
<objects>
167-
<viewController storyboardIdentifier="ScanVC" id="gra-LP-s25" customClass="ScanVC" customModule="DocScan" customModuleProvider="target" sceneMemberID="viewController">
167+
<viewController storyboardIdentifier="ScanVC" modalPresentationStyle="fullScreen" id="gra-LP-s25" customClass="ScanVC" customModule="DocScan" customModuleProvider="target" sceneMemberID="viewController">
168168
<view key="view" contentMode="scaleToFill" id="4Th-db-7p1">
169169
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/>
170170
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -250,7 +250,7 @@ save any of your data on servers.</string>
250250
<segue destination="dVl-B0-R3K" kind="show" id="T6k-yI-vPb"/>
251251
</connections>
252252
</barButtonItem>
253-
<barButtonItem style="plain" systemItem="add" id="fD3-sX-Dtq">
253+
<barButtonItem title="Item" image="folder.badge.plus" catalog="system" style="plain" id="fD3-sX-Dtq">
254254
<color key="tintColor" name="AppBlackColor"/>
255255
<connections>
256256
<action selector="showaddTapped:" destination="gra-LP-s25" id="01I-5T-kQn"/>
@@ -310,7 +310,7 @@ save any of your data on servers.</string>
310310
<!--Settings-->
311311
<scene sceneID="Qmc-7B-Mih">
312312
<objects>
313-
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="nwi-Mk-kM9" sceneMemberID="viewController">
313+
<navigationController automaticallyAdjustsScrollViewInsets="NO" modalPresentationStyle="pageSheet" id="nwi-Mk-kM9" sceneMemberID="viewController">
314314
<tabBarItem key="tabBarItem" title="Settings" image="Settings" id="woH-2Z-VIa"/>
315315
<toolbarItems/>
316316
<navigationItem key="navigationItem" id="3Jx-a5-oBD"/>
@@ -330,7 +330,7 @@ save any of your data on servers.</string>
330330
<!--Settings-->
331331
<scene sceneID="6vh-7b-4aL">
332332
<objects>
333-
<tableViewController id="FJl-wv-xDn" customClass="SettingsTableVC" customModule="DocScan" customModuleProvider="target" sceneMemberID="viewController">
333+
<tableViewController modalPresentationStyle="pageSheet" id="FJl-wv-xDn" customClass="SettingsTableVC" customModule="DocScan" customModuleProvider="target" sceneMemberID="viewController">
334334
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="insetGrouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="HXx-eo-skX">
335335
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
336336
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -430,7 +430,7 @@ save any of your data on servers.</string>
430430
<!--App Icons-->
431431
<scene sceneID="Bbw-tF-zqb">
432432
<objects>
433-
<viewController storyboardIdentifier="appIconsVC" hidesBottomBarWhenPushed="YES" id="7jF-h4-IiT" customClass="appIconsVC" customModule="DocScan" customModuleProvider="target" sceneMemberID="viewController">
433+
<viewController storyboardIdentifier="appIconsVC" modalPresentationStyle="pageSheet" hidesBottomBarWhenPushed="YES" id="7jF-h4-IiT" customClass="appIconsVC" customModule="DocScan" customModuleProvider="target" sceneMemberID="viewController">
434434
<view key="view" contentMode="scaleToFill" id="t4v-uA-R2j">
435435
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
436436
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -660,7 +660,7 @@ save any of your data on servers.</string>
660660
<size key="intrinsicContentSize" width="62" height="30"/>
661661
</designable>
662662
<designable name="YtD-Q7-T7Z">
663-
<size key="intrinsicContentSize" width="107" height="18.5"/>
663+
<size key="intrinsicContentSize" width="67" height="18.5"/>
664664
</designable>
665665
</designables>
666666
<color key="tintColor" name="AppBlackColor"/>
@@ -674,6 +674,7 @@ save any of your data on servers.</string>
674674
<image name="cloud" catalog="system" width="128" height="87"/>
675675
<image name="flame.fill" catalog="system" width="108" height="128"/>
676676
<image name="folder" catalog="system" width="128" height="97"/>
677+
<image name="folder.badge.plus" catalog="system" width="128" height="91"/>
677678
<image name="message" catalog="system" width="128" height="113"/>
678679
<namedColor name="AppBlackColor">
679680
<color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>

DocScan/VCs/2CameraSubVC/CameraVC.swift

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,39 @@ extension CameraVC:VNDocumentCameraViewControllerDelegate {
110110

111111
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
112112

113-
for pageNumber in 0..<scan.pageCount {
114-
let Outimage = scan.imageOfPage(at: pageNumber)
115-
imgView.image = scan.imageOfPage(at: 0)
116-
imgView2.image = scan.imageOfPage(at: 1)
113+
/*
114+
for pageNumber in 0..<scan.pageCount {
115+
let Outimage = scan.imageOfPage(at: pageNumber)
116+
imgView.image = scan.imageOfPage(at: 0)
117+
imgView2.image = scan.imageOfPage(at: 1)
118+
controller.dismiss(animated: true, completion: nil)
119+
*/
120+
guard scan.pageCount >= 1 else {
121+
controller.dismiss(animated: true)
122+
return
117123
}
118-
controller.dismiss(animated: true, completion: nil)
124+
print("Found \(scan.pageCount)")
125+
let pdfDocument = PDFDocument()
126+
127+
for i in 0 ..< scan.pageCount {
128+
let img = scan.imageOfPage(at: i)
129+
// ... your code here
130+
let pdfPage = PDFPage(image: img)
131+
pdfDocument.insert(pdfPage!, at: i)
132+
}
133+
let data = pdfDocument.dataRepresentation()
134+
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
135+
let docURL = documentDirectory.appendingPathComponent("Scanned-Docs.pdf")
136+
do{
137+
print("Documet: \(docURL)")
138+
try data?.write(to: docURL)
139+
}catch(let error){
140+
print("error is \(error.localizedDescription)")
141+
}
142+
// let originalImage = scan.imageOfPage(at: 0)
143+
// let newImage = compressedImage(originalImage)
144+
controller.dismiss(animated: true)
145+
// processImage(newImage)
119146
}
120147

121148
func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {

0 commit comments

Comments
 (0)