diff --git a/JustScanIt.xcodeproj/project.pbxproj b/JustScanIt.xcodeproj/project.pbxproj index 8be2a98..43a68db 100644 --- a/JustScanIt.xcodeproj/project.pbxproj +++ b/JustScanIt.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 460818AE2C3D68A90044FF7C /* PDFCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 460818AD2C3D68A90044FF7C /* PDFCreator.swift */; }; 46410F842C3D12B100FFBF7E /* ZoomableScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46410F832C3D12B100FFBF7E /* ZoomableScrollView.swift */; }; 466989C72C34DC7A009884D1 /* JustScanItApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466989C62C34DC7A009884D1 /* JustScanItApp.swift */; }; 466989CB2C34DC7B009884D1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 466989CA2C34DC7B009884D1 /* Assets.xcassets */; }; @@ -20,6 +21,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 460818AD2C3D68A90044FF7C /* PDFCreator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFCreator.swift; sourceTree = ""; }; 46410F832C3D12B100FFBF7E /* ZoomableScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomableScrollView.swift; sourceTree = ""; }; 466989C32C34DC7A009884D1 /* JustScanIt.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JustScanIt.app; sourceTree = BUILT_PRODUCTS_DIR; }; 466989C62C34DC7A009884D1 /* JustScanItApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustScanItApp.swift; sourceTree = ""; }; @@ -86,6 +88,7 @@ children = ( 466989D52C34DCE4009884D1 /* VNDocumentCameraViewControllerR.swift */, 46410F832C3D12B100FFBF7E /* ZoomableScrollView.swift */, + 460818AD2C3D68A90044FF7C /* PDFCreator.swift */, ); path = Controllers; sourceTree = ""; @@ -187,6 +190,7 @@ 466989D62C34DCE4009884D1 /* VNDocumentCameraViewControllerR.swift in Sources */, 46410F842C3D12B100FFBF7E /* ZoomableScrollView.swift in Sources */, 466989DD2C35299D009884D1 /* ScanItemView.swift in Sources */, + 460818AE2C3D68A90044FF7C /* PDFCreator.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -245,7 +249,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 17.5; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; @@ -302,7 +306,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 17.5; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; diff --git a/JustScanIt/Assets.xcassets/AppIcon.appiconset/Contents.json b/JustScanIt/Assets.xcassets/AppIcon.appiconset/Contents.json index 7efa25a..b19fbcf 100644 --- a/JustScanIt/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/JustScanIt/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "icon_dark2.png", + "filename" : "icon2.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" diff --git a/JustScanIt/Assets.xcassets/AppIcon.appiconset/icon2.png b/JustScanIt/Assets.xcassets/AppIcon.appiconset/icon2.png new file mode 100644 index 0000000..df8b943 Binary files /dev/null and b/JustScanIt/Assets.xcassets/AppIcon.appiconset/icon2.png differ diff --git a/JustScanIt/Assets.xcassets/AppIcon.appiconset/icon_dark2.png b/JustScanIt/Assets.xcassets/AppIcon.appiconset/icon_dark2.png deleted file mode 100644 index 389f18a..0000000 Binary files a/JustScanIt/Assets.xcassets/AppIcon.appiconset/icon_dark2.png and /dev/null differ diff --git a/JustScanIt/Controllers/PDFCreator.swift b/JustScanIt/Controllers/PDFCreator.swift new file mode 100644 index 0000000..cbb1720 --- /dev/null +++ b/JustScanIt/Controllers/PDFCreator.swift @@ -0,0 +1,16 @@ +// +// PDFCreator.swift +// JustScanIt +// +// Created by Pradyun Setti on 10/07/2024. +// + +import Foundation + +public final class PDFCreator { + private let dpi: CGFloat = 72 + + public func generate() { + + } +} diff --git a/JustScanIt/View/ScanItemView.swift b/JustScanIt/View/ScanItemView.swift index 546339d..826be6e 100644 --- a/JustScanIt/View/ScanItemView.swift +++ b/JustScanIt/View/ScanItemView.swift @@ -15,17 +15,40 @@ struct ScanItemView: View { let scan: Scan let images: [Image] -// let uiImages: [UIImage] private let translucentColour = Color(red: 0.6, green: 0.8, blue: 1, opacity: 0.4) private let bgBottomColour = Color(red: 33/255, green: 90/255, blue: 1, opacity: 1) private let bgTopColour = Color(red: 0/255, green: 130/255, blue: 1, opacity: 1) + var sharePDFURL: URL! = nil + + @MainActor init(_ scan: Scan) { self.scan = scan - self.images = scan.toSwiftUIImages() -// self.uiImages = scan.toUIImages() + let imgs = scan.toSwiftUIImages() + self.images = imgs + + let rect = CGRect(x: 0, y: 0, width: 8.27*72, height: 11.69*72) // A4 dimensions multiplied by 72 dpi + + let format = UIGraphicsPDFRendererFormat() + + let renderer = UIGraphicsPDFRenderer(bounds: rect, format: format) + let tempFolder = FileManager.default.temporaryDirectory + + let fileName = "scan.pdf" + let tempURL = tempFolder.appendingPathComponent(fileName) + + try? renderer.writePDF(to: tempURL) { context in + for img in imgs { + context.beginPage() + let imageRenderer = ImageRenderer(content: img.resizable().scaledToFit()) + imageRenderer.scale = 1 + imageRenderer.uiImage?.draw(at: CGPoint.zero) + } + } + + self.sharePDFURL = tempURL } var body: some View { @@ -64,13 +87,23 @@ struct ScanItemView: View { .clipShape(Circle()) } - ShareLink(items: self.images, preview: { _ in SharePreview("Scan", image: self.images.first!)} ) { + Menu { + ShareLink(items: self.images, preview: { _ in SharePreview("Scan", image: self.images.first!)} ) { + Label("PNG", systemImage: "square.and.arrow.up") + } + ShareLink(item: self.sharePDFURL) { + Label("PDF", systemImage: "square.and.arrow.up") + } + + } label: { Image(systemName: "square.and.arrow.up").tint(.white) .padding(8) .background(translucentColour) .offset(y: -2) .clipShape(Circle()) } + + Button { delete() } label: { Image(systemName: "xmark").bold().tint(.red) @@ -78,15 +111,14 @@ struct ScanItemView: View { .background(translucentColour) .clipShape(Circle()) } + .contextMenu { + Button("Delete All Scans", role: .destructive) { + deleteAll() + } + } + } .shadow(radius: 6, y: 0) - - .contextMenu(menuItems: { - Button("Delete All Scans", role: .destructive) { - deleteAll() - } - }) -// } if isZoomed { @@ -132,6 +164,7 @@ struct ScanItemView: View { try? ctx.save() } } + } #Preview { diff --git a/icon.pxd b/icon.pxd index 0b8542a..70b94ec 100644 Binary files a/icon.pxd and b/icon.pxd differ diff --git a/icon2.png b/icon2.png new file mode 100644 index 0000000..df8b943 Binary files /dev/null and b/icon2.png differ