Added Menu to share between pdf and pngs
This commit is contained in:
parent
65a281d982
commit
1ab1e3a5f5
@ -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 = "<group>"; };
|
||||
46410F832C3D12B100FFBF7E /* ZoomableScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomableScrollView.swift; sourceTree = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
@ -86,6 +88,7 @@
|
||||
children = (
|
||||
466989D52C34DCE4009884D1 /* VNDocumentCameraViewControllerR.swift */,
|
||||
46410F832C3D12B100FFBF7E /* ZoomableScrollView.swift */,
|
||||
460818AD2C3D68A90044FF7C /* PDFCreator.swift */,
|
||||
);
|
||||
path = Controllers;
|
||||
sourceTree = "<group>";
|
||||
@ -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;
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_dark2.png",
|
||||
"filename" : "icon2.png",
|
||||
"idiom" : "universal",
|
||||
"platform" : "ios",
|
||||
"size" : "1024x1024"
|
||||
|
BIN
JustScanIt/Assets.xcassets/AppIcon.appiconset/icon2.png
Normal file
BIN
JustScanIt/Assets.xcassets/AppIcon.appiconset/icon2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 142 KiB |
Binary file not shown.
Before Width: | Height: | Size: 118 KiB |
16
JustScanIt/Controllers/PDFCreator.swift
Normal file
16
JustScanIt/Controllers/PDFCreator.swift
Normal file
@ -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() {
|
||||
|
||||
}
|
||||
}
|
@ -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,7 +87,15 @@ 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)
|
||||
@ -72,21 +103,22 @@ struct ScanItemView: View {
|
||||
.clipShape(Circle())
|
||||
}
|
||||
|
||||
|
||||
|
||||
Button { delete() } label: {
|
||||
Image(systemName: "xmark").bold().tint(.red)
|
||||
.padding(8)
|
||||
.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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user