Skip to content

PrintingKit is a Swift-based SDK that helps you print in Swift and SwiftUI.

License

Notifications You must be signed in to change notification settings

FlineDevPublic/PrintingKit

 
 

Repository files navigation

PrintingKit Logo

Version Swift 5.9 MIT License Twitter: @danielsaidi Mastodon: @danielsaidi@mastodon.social

About PrintingKit

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.

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

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.

Documentation

The online documentation has more information, code examples, etc.

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 my work

You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.

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.

About

PrintingKit is a Swift-based SDK that helps you print in Swift and SwiftUI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 88.7%
  • Ruby 11.3%