All Projects → sgr-ksmt → Pdfgenerator

sgr-ksmt / Pdfgenerator

Licence: mit
A simple generator of PDF written in Swift.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Pdfgenerator

Haptica
Easy Haptic Feedback Generator 📳
Stars: ✭ 587 (-6.68%)
Mutual labels:  cocoapods, carthage, generator
Uxmpdfkit
An iOS PDF viewer and annotator written in Swift that can be embedded into any application.
Stars: ✭ 260 (-58.66%)
Mutual labels:  pdf, cocoapods, carthage
Peep
Easy Sound Generator 🐥
Stars: ✭ 59 (-90.62%)
Mutual labels:  cocoapods, carthage, generator
Tppdf
TPPDF is a simple-to-use PDF builder for iOS
Stars: ✭ 444 (-29.41%)
Mutual labels:  pdf, cocoapods, generator
Openssl
OpenSSL package for SPM, CocoaPod, and Carthage, for iOS and macOS
Stars: ✭ 515 (-18.12%)
Mutual labels:  cocoapods, carthage
Keyboardshortcuts
Add user-customizable global keyboard shortcuts to your macOS app in minutes
Stars: ✭ 500 (-20.51%)
Mutual labels:  cocoapods, carthage
Multiprogressview
📊 An animatable view that depicts multiple progresses over time. Modeled after UIProgressView
Stars: ✭ 614 (-2.38%)
Mutual labels:  cocoapods, carthage
Orsserialport
Serial port library for Objective-C and Swift macOS apps
Stars: ✭ 609 (-3.18%)
Mutual labels:  cocoapods, carthage
Xmlcoder
Easy XML parsing using Codable protocols in Swift
Stars: ✭ 460 (-26.87%)
Mutual labels:  cocoapods, carthage
Swiftframeworktemplate
A template for new Swift iOS / macOS / tvOS / watchOS Framework project ready with travis-ci, cocoapods, Carthage, SwiftPM and a Readme file
Stars: ✭ 527 (-16.22%)
Mutual labels:  cocoapods, carthage
Gradientview
Easily use gradients in UIKit for iOS & tvOS
Stars: ✭ 610 (-3.02%)
Mutual labels:  cocoapods, carthage
Watchdoginspector
Shows your current framerate (fps) in the status bar of your iOS app
Stars: ✭ 497 (-20.99%)
Mutual labels:  cocoapods, carthage
Youtubekit
YoutubeKit is a video player that fully supports Youtube IFrame API and YoutubeDataAPI for easily create a Youtube app
Stars: ✭ 484 (-23.05%)
Mutual labels:  cocoapods, carthage
Anim
Swift animation library for iOS, tvOS and macOS.
Stars: ✭ 520 (-17.33%)
Mutual labels:  cocoapods, carthage
Googlereporter
Easily integrate with Google Analytics in your iOS app
Stars: ✭ 479 (-23.85%)
Mutual labels:  cocoapods, carthage
Swiftoverlays
SwiftOverlays is a Swift GUI library for displaying various popups and notifications
Stars: ✭ 621 (-1.27%)
Mutual labels:  cocoapods, carthage
Sdwebimage
Asynchronous image downloader with cache support as a UIImageView category
Stars: ✭ 23,928 (+3704.13%)
Mutual labels:  cocoapods, carthage
Sablurimageview
You can use blur effect and it's animation easily to call only two methods.
Stars: ✭ 538 (-14.47%)
Mutual labels:  cocoapods, carthage
Swiftinstagram
Instagram API client written in Swift
Stars: ✭ 570 (-9.38%)
Mutual labels:  cocoapods, carthage
Agrume
🍋 A lemony fresh iOS image viewer written in Swift.
Stars: ✭ 449 (-28.62%)
Mutual labels:  cocoapods, carthage

Features | Requirements | Installation | Usage | Communication | LICENSE

PDFGenerator

Build Status GitHub release codecov Language Carthage CocoaPods CocoaPodsDL Awesome Reviewed by Hound

PDFGenerator is a simple PDF generator that generates with UIView, UIImage, ...etc .

do {
    let page: [PDFPage] = [
        .whitePage(CGSize(width: 200.0, height: 100.0)),
        .image(image1)
        .image(image2)
        .imagePath(lastPageImagePath)
        .whitePage(CGSize(width: 200.0, height: 100.0))
    ]
    let path = NSTemporaryDirectory().appending("sample1.pdf")
    try PDFGenerator.generate(page, to: path, password: "123456")
} catch let error {
    print(error)
}

Features

  • Swift 5 is ready 🙏
  • Multiple pages support.
  • Also generate PDF with image path, image binary, image ref (CGImage)
  • Good memory management.
  • UIScrollView support : If view is UIScrollView, UITableView, UICollectionView, UIWebView, drawn whole content.
  • Outputs as binary(Data) or writes to Disk(in given file path) directly.
  • Corresponding to Error-Handling. Strange PDF has never been generated!!.
  • DPI support. : Default dpi is 72.
  • Password protection support.

Requirements

  • iOS 9.0+
  • Xcode 11+
  • Swift 5.1

Installation

Carthage

  • Add the following to your Cartfile:
github "sgr-ksmt/PDFGenerator" ~> 3.1
  • Then run command:
$ carthage update

CocoaPods

PDFGenerator is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'PDFGenerator', '~> 3.1'

and run pod install

Usage

Generate from view(s) or image(s)

  • UIView → PDF
func generatePDF() {
    let v1 = UIScrollView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 100.0))
    let v2 = UIView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 200.0))
    let v3 = UIView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 200.0))
    v1.backgroundColor = .red
    v1.contentSize = CGSize(width: 100.0, height: 200.0)
    v2.backgroundColor = .green
    v3.backgroundColor = .blue

    let dst = URL(fileURLWithPath: NSTemporaryDirectory().appending("sample1.pdf"))
    // outputs as Data
    do {
        let data = try PDFGenerator.generated(by: [v1, v2, v3])
        try data.write(to: dst, options: .atomic)
    } catch (let error) {
        print(error)
    }

    // writes to Disk directly.
    do {
        try PDFGenerator.generate([v1, v2, v3], to: dst)    
    } catch (let error) {
        print(error)
    }
}

Also PDF can generate from image(s), image path(s) same as example.

Generate from PDFPage object

  • (UIVIew or UIImage) → PDF

Use PDFPage.

public enum PDFPage {
    case whitePage(CGSize) // = A white view
    case view(UIView)
    case image(UIImage)
    case imagePath(String)
    case binary(Data)
    case imageRef(CGImage)
}
func generatePDF() {
    let v1 = UIView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 100.0))
    v1.backgroundColor = .red
    let v2 = UIView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 200.0))
    v2.backgroundColor = .green

    let page1 = PDFPage.View(v1)
    let page2 = PDFPage.View(v2)
    let page3 = PDFPage.WhitePage(CGSizeMake(200, 100))
    let page4 = PDFPage.Image(UIImage(contentsOfFile: "path/to/image1.png")!)
    let page5 = PDFPage.ImagePath("path/to/image2.png")
    let pages = [page1, page2, page3, page4, page5]

    let dst = NSTemporaryDirectory().appending("sample1.pdf")
    do {
        try PDFGenerator.generate(pages, to: dst)
    } catch (let e) {
        print(e)
    }
}

Generate custom dpi PDF

// generate dpi300 PDF (default: 72dpi)
func generatePDF() {
    let v1 = UIView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 100.0))
    v1.backgroundColor = .red
    let v2 = UIView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 200.0))
    v2.backgroundColor = .green

    let page1 = PDFPage.View(v1)
    let page2 = PDFPage.View(v2)
    let pages = [page1, page2]

    let dst = NSTemporaryDirectory().appending("sample1.pdf")
    do {
        try PDFGenerator.generate(pages, to: dst, dpi: .dpi_300)
    } catch (let e) {
        print(e)
    }
}

Password protection

// generate PDF with password: 123456
func generatePDF() {
    let v1 = UIView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 100.0))
    v1.backgroundColor = .red
    let v2 = UIView(frame: CGRect(x: 0.0,y: 0, width: 100.0, height: 200.0))
    v2.backgroundColor = .green

    let page1 = PDFPage.view(v1)
    let page2 = PDFPage.view(v2)
    let pages = [page1, page2]

    let dst = NSTemporaryDirectory().appending("sample1.pdf")
    do {
        try PDFGenerator.generate(pages, to: dst, password: "123456")
        // or use PDFPassword model
        try PDFGenerator.generate(pages, to: dst, password: PDFPassword("123456"))
        // or use PDFPassword model and set user/owner password
        try PDFGenerator.generate(pages, to: dst, password: PDFPassword(user: "123456", owner: "abcdef"))
    } catch let error {
        print(error)
    }
}

Communication

  • If you found a bug, please open an issue. 🙇
  • Also, if you have a feature request, please open an issue. 👍
  • If you want to contribute, submit a pull request.💪

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].