import AppKit import Foundation import PDFKit func fail(_ message: String) -> Never { FileHandle.standardError.write((message + "\n").data(using: .utf8)!) exit(1) } guard CommandLine.arguments.count == 4 else { fail("usage: pdf-render ") } let input = URL(fileURLWithPath: CommandLine.arguments[1]) let outputDirectory = URL(fileURLWithPath: CommandLine.arguments[2], isDirectory: true) let extensionName = CommandLine.arguments[3].lowercased() let fileType: NSBitmapImageRep.FileType switch extensionName { case "png": fileType = .png case "jpg", "jpeg": fileType = .jpeg case "tif", "tiff": fileType = .tiff default: fail("unsupported image format: \(extensionName)") } try FileManager.default.createDirectory(at: outputDirectory, withIntermediateDirectories: true) guard let document = PDFDocument(url: input) else { fail("could not open PDF: \(input.path)") } for index in 0..