Last active
May 20, 2024 07:03
-
-
Save kidGodzilla/9d500630b77d12880a4834ac9d94d886 to your computer and use it in GitHub Desktop.
PDF to PNG Script for Quickdrop App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PDF to PNG shell script for Quickdrop app | |
# https://quickdrop.antran.app/ | |
# pdfburst shell script | |
# chmod 0755 pdfburst | |
#!/usr/bin/swift | |
import Foundation | |
import PDFKit | |
func splitPDF(inputPath: String) { | |
let docURL = URL(fileURLWithPath: inputPath) | |
guard let pdfDocument = PDFDocument(url: docURL) else { | |
print("Error: Unable to open PDF at \(inputPath)") | |
return | |
} | |
guard pdfDocument.pageCount > 1 else { | |
print(inputPath) | |
return | |
} | |
let baseFileName = docURL.deletingPathExtension() | |
for i in 0..<pdfDocument.pageCount { | |
guard let page = pdfDocument.page(at: i) else { continue } | |
let newDocument = PDFDocument() | |
newDocument.insert(page, at: 0) | |
let outputPath = baseFileName.path(percentEncoded: false) + "_page_\(i+1).pdf" | |
newDocument.write(to: URL(fileURLWithPath: outputPath)) | |
print(outputPath) | |
} | |
} | |
if CommandLine.arguments.count < 2 { | |
print("Usage: \(CommandLine.arguments.first!) <inputPDF>") | |
exit(1) | |
} | |
let inputPath = CommandLine.arguments[1] | |
splitPDF(inputPath: inputPath) | |
# PDF to PNG Shell Script | |
/usr/local/bin/pdfburst "{{inputFilePath}}" | awk '{print "/usr/bin/sips -s format png \"" $NF "\" -z 2112 1632 --out \"" $0 ".png\"; rm -f \"" $NF "\""}' | bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome @kidGodzilla. It's even more awesome that it is written in Swift 🥳