PrintingKit helps you print PDF documents, images, etc. in Swift and SwiftUI.
With PrintingKit, you just have to create a Printer
instance or use Printer.shared
, then use it to print any of the supported PrintItem
types with a single line of code.
PrintingKit works on both iOS and macOS.
PrintingKit can be installed with the Swift Package Manager:
https://github.com/danielsaidi/PrintingKit.git
If you prefer to not have external dependencies, you can also just copy the source code into your app.
PrintingKit currently supports the following PrintItem
types:
.attributedString(_:configuration:)
- an attributed string..imageData(_:)
- JPG or PNG data..imageFile(at:)
- a JPG or PNG file at a certain URL..pdfData(_:)
- PDF document data..pdfFile(at:)
- a PDF document file at a certain URL..string(_:configuration:)
- a plain string..view(_:withScale:)
- any SwiftUI view.
To print any of the supported items, just use a Printer
instance, or Printer.shared
:
struct MyView: View {
let printer = Printer()
var body: some View {
VStack {
Button("Print PDF") {
try? printer.print(.pdf(at: anyUrl))
}
Button("Print view") {
try? printer.print(image)
}
Button("Print view without try") {
printer.printInTask(image)
}
}
}
}
For more information, see the getting started.
The online documentation has more information, code examples, etc.
The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the Demo
project.
You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.
Feel free to reach out if you have questions or if you want to contribute in any way:
- Website: danielsaidi.com
- Mastodon: @[email protected]
- Twitter: @danielsaidi
- E-mail: [email protected]
PrintingKit is available under the MIT license. See the LICENSE file for more info.