A Swift-based SDK that helps you print in Swift and SwiftUI

About PrintingKit

PrintingKit helps you print PDF documents, images, etc. in Swift and SwiftUI.

For instance, to print a PDF file in the main bundle, just do this:

let bundle = Bundle.main
let url = bundle.url(forResource: "doc", withExtension: "pdf")
let item = PrintItem.pdfFile(at: url)
try? StandardPrinter().print(item)

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.

PrintingKit supports iOS 13 and macOS 11.

Installation

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.

Getting started

The online documentation has a getting started guide that helps you get started with PrintingKit.

For instance, to print a PDF in SwiftUI, just do this:

struct MyView: View {

    var body: some View {
        Button("Print document") {
            let bundle = Bundle.main
            let url = bundle.url(forResource: "doc", withExtension: "pdf")
            let item = PrintItem.pdf(at: url)
            try? StandardPrinter().print(item)
        }
    }
}

You can also let your views implement PrinterView to make printing even easier.

For more information, see the getting started.

Documentation

The online documentation has more information, code examples, etc., and lets you overview the various parts of the library.

Demo Application

The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the Demo project.

Support this library

I manage my various open-source projects in my free time and am really thankful for any help I can get from the community.

You can sponsor this project on GitHub Sponsors or get in touch for paid support.

Contact

Feel free to reach out if you have questions or if you want to contribute in any way:

License

PrintingKit is available under the MIT license. See the LICENSE file for more info.

GitHub

View Github