Giter VIP home page Giter VIP logo

pdftools's Introduction

PDFTools

A recent app I was working on called for a simplistic level of reporting and to be able to save those reports to disk or print them. I searched around for a reporting library that I could use with Swift on iOS and failed to find anything. Not just anything I could afford (ideally open source) but anything at all.

So, PDFTools was my next step. It needed to fill two aspects;

  • To be able to view PDF files and export/print them.
  • To be able to generate PDF files in the simplest way possible without needing to understand the complexities of the PDF file format.

This is a work in progress - it is being developed along side a somewhat larger project - I will be evolving the functionality of the library over time as my larger apps requirements change. I have a number of requirements that I know I will need to fulfil in future versions. The state of this app as I first publish it is that it does display/print/export PDF files and it does generate a reasonably good looking PDF file.

I have included a test app in the repo that illustrates the use of the basic page components. It needs a lot more testing than I have done to date, but that will come from usage.

Overview

I took a declarative approach to creating PDF files. So, my caller creates an instance of the generator then adds components to the page. The final step is to then generate the document. For example...

        let generator = PDFGenerator(creator: "Test App",
                                     author: "Steve",
                                     title: "Test PDF File")

Having created the generator, we add the page components.

        generator.document.add(PDFSetCursor(newCursor: 200))
        generator.document.add(PDFBox(height: 40))
        generator.document.add(PDFParagraph(style: .title, text: "Joanna Masters"))
        generator.document.add(PDFParagraph(style: .subtitle, text: "CAA-12345-FJW"))
        generator.document.add(PDFImage(image: UIImage(named: "waitingInLine")!))
        generator.document.add(PDFLine(lineWidth: 4))
        generator.document.add(PDFSpacer(gap: 10))

        generator.document.add(PDFParagraph(style: .heading1, text: "Pilot Biography"))
        generator.document.add(PDFParagraph(style: .normal, text: "Brief introduction to the pilot and some of" +
                                       "their background in the flying world."))

Finally, we generate the PDF.

        var pdfData = generator.render()

The data returned contains the PDF file contents. You can save it to a file or push it into the viewer component:

    @State private var pdfData: Data?

    var body: some View {
        VStack {
            PDFViewer(pdfData: pdfData)
        }
    }

pdftools's People

Contributors

sabarnett avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.