Go to file
Sergej Jaskiewicz bcc8a3caea Fix CocoaPods build 2019-01-09 01:24:22 +03:00
.scripts Attempt to make the tests pass 2018-12-21 17:34:51 +03:00
Demo #2: Implement Text demo 2019-01-08 20:15:13 +03:00
Sources Fix CocoaPods build 2019-01-09 01:24:22 +03:00
Tests Implement measuring text, setting character and word spacing 2018-12-25 16:46:08 +03:00
docs Regenerate docs 2018-12-24 21:41:19 +03:00
.codecov.yml Attempt configuring Codecov 2016-10-02 02:14:55 +03:00
.gitignore Drop DefaultStringConvertible dependency 2017-06-18 22:58:40 +03:00
.travis.yml Fix failing `pod lib lint` 2018-12-24 00:12:51 +03:00
CHANGELOG.md Update the changelog 2019-01-09 01:15:11 +03:00
FEATURES.md Implement measuring text, setting character and word spacing 2018-12-25 16:46:08 +03:00
LICENSE Add LICENSE file 2016-10-27 11:27:07 +03:00
Makefile Regenerate docs 2018-12-24 21:04:46 +03:00
Package.swift Adopt SnapshotTesting framework 2018-12-22 02:57:49 +03:00
README.md Regenerate docs 2018-12-24 21:04:46 +03:00
SwiftyHaru.podspec Regenerate docs 2018-12-24 21:04:46 +03:00

README.md

SwiftyHaru

Build Status codecov documentation Language Platform Cocoapods

SwiftyHaru is an object-oriented Swift wrapper for LibHaru, a C library for creating PDF documents. It brings the safety of Swift to the process of creating PDFs on different platforms like Linux, macOS, iOS, watchOS and tvOS.

Check out which features of LibHaru has already been implemented in FEATURES.md

Requirements

  • Swift 4.2+
  • iOS 8.0+
  • macOS 10.10+
  • tvOS 9.0+
  • watchOS 2.0+
  • Ubuntu 14.04+

Installation

CocoaPods

For the latest release in CocoaPods add the following to your Podfile:

use_frameworks!

pod 'SwiftyHaru'

For the latest dev build:

use_frameworks!

pod 'SwiftyHaru', :git => 'https://github.com/WeirdMath/SwiftyHaru.git', :branch => 'dev'

Swift Package Manager

Add SwiftyHaru as a dependency to your Package.swift. For example:

let package = Package(
    name: "YourPackageName",
    dependencies: [
        .package(url: "https://github.com/WeirdMath/SwiftyHaru.git", from: "0.3.0")
    ]
)

Important: when building your project that has SwiftyHaru as a dependency, you need to pass the -Xlinker -lz flags to the compiler. This is because SwiftyHaru has to be linked with zlib (which must be intalled on your computer). For example:

$ swift build -Xlinker -lz
$ swift test -Xlinker -lz

Documentation

Available here.

Getting started

import SwiftyHaru

// Initialize stuff
let document = PDFDocument()

try document.addPage(width: 600, height: 400) { context in

    // Construct a path
    let path = Path()
        .moving(toX: 100, y: 100)
        .appendingLine(toX: 400, y: 100)
        .moving(toX: 500, y: 200)
        .appendingArc(x: 400, y: 200, radius: 100, beginningAngle: 90, endAngle: 180)
        .appendingCircle(x: 200, y: 200, radius: 50)
        .moving(toX: 500, y: 200)
        .appendingCurve(controlPoint1: Point(x: 400, y: 200),
                        controlPoint2: Point(x: 400, y: 300),
                        endPoint: Point(x: 500, y: 300))
        .closingSubpath()

    // Paint the path
    context.strokeColor = .blue
    context.stroke(path)

    // Put some text
    context.textLeading = 11
    try context.show(text: "Roses are red,\nViolets are blue,\nSugar is sweet,\nAnd so are you.",
                     atX: 300, y: 200)
}

Contributing

Building:

$ make debug

Or:

$ make release

Testing:

$ make test

Generating Xcode project

Since the Xcode project is explicitly gitignored, you might want to generate it in order to make development comfortable for you. This can be accomplished by running the following command:

make generate-xcodeproj