Skip to content

Commit

Permalink
Merge pull request #6 from newportsolutionsgroup/newportsolutions-fea…
Browse files Browse the repository at this point in the history
…ture-compressionQuality

compress scanned images when creating a PDF file
  • Loading branch information
hansemannn authored Dec 11, 2021
2 parents c5bcb7b + 367c701 commit eba2b21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Classes/TiScannerModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,23 @@ class TiScannerModule: TiModule {

var resizeImages = false
var padding = 80
var compressionQuality = 1.0

if let params = args?.first as? [String: Any] {
resizeImages = params["resizeImages"] as? Bool ?? false
padding = params["padding"] as? Int ?? 80
compressionQuality = params["compressionQuality"] as? Double ?? 1.0
}

let pdfDocument = PDFDocument()

for index in 0...scan.pageCount - 1 {
let image = scan.imageOfPage(at: index)
//let image = scan.imageOfPage(at: index)
let image = UIImage(data: scan.imageOfPage(at: index).jpegData(compressionQuality: compressionQuality)!)

if resizeImages {
// Get the raw data representation
if let pdfData = A4PDFDataFromCentered(image: image, with: Float(padding)) {
if let pdfData = A4PDFDataFromCentered(image: image!, with: Float(padding)) {
// Generate a PDF document from the raw data
if let pdfDataDocument = PDFDocument(data: pdfData) {
// Get the page from the generate document
Expand All @@ -106,7 +109,7 @@ class TiScannerModule: TiModule {
}
}
} else {
if let pdfPage = PDFPage(image: image) {
if let pdfPage = PDFPage(image: image!) {
pdfDocument.insert(pdfPage, at: index)
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 3.0.1
version: 3.0.2
apiversion: 2
architectures: arm64 x86_64
description: titanium-scanner
Expand Down

0 comments on commit eba2b21

Please sign in to comment.