SimplePDF is a wrapper of UIGraphics PDF context written in Swift.

Related tags

PDF SimplePDF
Overview

Simple PDF

Platform: iOS 8.0+ Language: Swift 4 Cocoapods

SimplePDF is a wrapper of UIGraphics PDF context written in Swift.

You can:

  • add texts, images, spaces and lines, table
  • set up page layout, adjust content alignment
  • generate PDF data/file.

In summary, you can create a simple PDF effortlessly. 😄

Example

let A4paperSize = CGSize(width: 595, height: 842)
let pdf = SimplePDF(pageSize: A4paperSize)

pdf.addText("Hello World!")
// or
// pdf.addText("Hello World!", font: myFont, textColor: myTextColor)

pdf.addImage( anImage )

let dataArray = [["Test1", "Test2"],["Test3", "Test4"]]
pdf.addTable(rowCount: 2, columnCount: 2, rowHeight: 20.0, columnWidth: 30.0, tableLineWidth: 1.0, font: UIFont.systemFontOfSize(5.0), dataArray: dataArray)

let pdfData = pdf.generatePDFdata()

// save as a local file
try? pdfData.writeToFile(path, options: .DataWritingAtomic)

See the result example.pdf, which is generated from ExampleCode.swift.

Installation

via Cocoapods

use_frameworks!
pod 'SimplePDF'

Usage

import SimplePDF

Page Setup

page setup

let A4paperSize = CGSize(width: 595, height: 842)
let pdf = SimplePDF(pageSize: A4paperSize, pageMargin: 20.0)
// or define all margins extra
let pdf = SimplePDF(pageSize: A4paperSize, pageMarginLeft: 35, pageMarginTop: 50, pageMarginBottom: 40, pageMarginRight: 35)

Write Something

pdf.addText( "some text" )
pdf.addImage( UIImage )
pdf.addAttributedText( NSAttributedString )
pdf.addLineSeparator(height: 30) // or pdf.addLineSeparator() default height is 1.0
pdf.addLineSpace(20)

Layout

You can layout horizontally and vertically

// Start a horizonal arrangement
pdf.beginHorizontalArrangement()
// Add space from the left
pdf.addHorizontalSpace(60)            

// now add your text, table, image, ...

// finishe the horizontal arrangement so you can continue vertically
pdf.endHorizontalArrangement()

// adds a vertical space
pdf.addVerticalSpace(70)

Table Definitions

Define the layout of tables with definitions

let tableDef = TableDefinition(alignments: [.left, .left],
                               columnWidths: [100, 300],
                               fonts: [UIFont.systemFont(ofSize: 20),
                                       UIFont.systemFont(ofSize: 16)],
                               textColors: [UIColor.black,
                                            UIColor.blue])
         
let data = [] // my data
         
pdf.addTable(data.count, 
             columnCount: 2, 
             rowHeight: 25, 
             tableLineWidth: 0, // this is taken from the definition
             tableDefinition: tableDef, 
             dataArray: data)

Utilities

pdf.beginNewPage() // Begin a new page

These following commands will affect everything you write after you call.

pdf.setContentAlignment(.Center) // .Left, .Center, .Right

Generate PDF data

let pdfData = pdf.generatePDFdata()

// write to file
try? pdfData.writeToFile(path, options: .DataWritingAtomic)

// or upload to Internet
// For example, Alamofire.upload(...)

License

SimplePDF is available under the MIT License.

Authors

Nutchaphon Rewik

my twitter

Comments
  • Table extensions

    Table extensions

    Hi, first of all, great library.

    I'm working a lot with tables and would like to make some extensions there. First the content alignment is not taken into account for table which means text is always centered. Second it would be great to pass attributed text to a table which give great flexibility in displaying.

    If you don't mind I will implement this and create a PR?

    opened by mrichtsfeld 8
  • Issue with compile errors

    Issue with compile errors

    I added this to my project, but I m getting compile errors in SimplePDF.swift => drawtext

        let attributes: [NSAttributedStringKey: Any] = [
            .font: font,
            .foregroundColor: textColor,
            .paragraphStyle: paragraphStyle
        ]
    

    Type 'NSString' has no member 'font'

        let attributes: [NSAttributedStringKey: Any] = [
            .foregroundColor: textColor,
            .paragraphStyle: paraStyle,
            .obliqueness: skew,
            .font: font
        ]
    

    Type 'NSString' has no member 'foregroundColor'

    Any clues?

    opened by f15radar 6
  • Alignments don't work in a table

    Alignments don't work in a table

    Hi there and thank you for this great library.

    I noticed that alignments don't work when creating tables. It is always aligned to the left. Trying center and right has no effect.

    Just following the example from the main page:

    let tableDef = TableDefinition(alignments: [.center, .right],
                                            columnWidths: [200, 200],
                                            fonts: [UIFont.systemFont(ofSize: 16), UIFont.systemFont(ofSize: 16)],
                                            textColors: [UIColor.black, UIColor.blue])
    
    
            let data = [["test1","test1"]]
    
            pdf.addTable(data.count,
                         columnCount: 2,
                         rowHeight: 25,
                         tableLineWidth: 0, // this is taken from the definition
                tableDefinition: tableDef,
                dataArray: data)
    

    I'm using 4.5.1 from cocoapods. Any ideas?

    opened by ozitrance 2
  • Podspec platform

    Podspec platform

    I am currently working on a project with a minimum platform target of iOS 8.0 and need to generate a PDF. I found this library and tried to install it via cocoapods and found that i was unable to do so because of the platform in your podspec is :ios, "9.0".

    So, I just tried to add the file SimplePDF.swift to the project and use it and found I was able to compile and use your library without problems.

    Could you set your podspec's platform to `:ios, "8.0"``?

    opened by jaceee 2
  • Architecture error

    Architecture error

    Not sure if this is related to this repository, but I'm getting an error: "Could not find module 'SimplePDF' for target 'arm64-apple-ios-simulator'; found x86_64-apple-ios-simulator, at: /Users/Owner/Library/Developer/Xcode/DerivedData/Bizzy_Books-elclaesdwnetyuhhuzftdvwifm/Index.noindex/Build/Products/Debug-iphonesimulator/SimplePDF/SimplePDF.framework/Modules/SimplePDF.swiftmodule.

    I think my iMac running Xcode has Intel x86_64.

    opened by caldwbr 1
  • Different alignment of content in a cells

    Different alignment of content in a cells

    Added content alignment from the table definition. If the definition of the table is not defined, then the content equalization is taken from the property transferred to the function.

    opened by Belzik 0
  • How to add a digital signature field

    How to add a digital signature field

    Is there a pdf.addDigitalSignatureField option? If not, is there any way to improvise this?

    My app is programmatically generating a work contract for construction business owners to automatically email to their potential customer and have a field for customer to digitally sign, save, and return back via email.

    Thanks!!!

    opened by caldwbr 1
  • How to begin new page automatically

    How to begin new page automatically

    Hi there,

    how can we determine page height according to content, basically i have define pagesize but unable to begin new page as data is overlapping in single page

    can you help me out how can start new page automatically

    opened by hitesh-shukla 2
  • Support for macOS

    Support for macOS

    Since a pdf generation tool like SimplePDF is quite general, I thought if it might be possible to make it compatible with macOS, and not only iOS?

    If I add the project to a macOS project, I get the following error.

    The platform of the target `TARGET NAME` (macOS 10.10) is not compatible with `SimplePDF (3.0.0)`, which does not support `osx`.

    opened by viktorstrate 1
  • How to add multiple images in a single row?

    How to add multiple images in a single row?

    In Pdf I have add lot of images, It displays vertically column vice but I want to add images horizontally row vice. It is possible to add images in single row.?

    opened by Saravana181187 0
Releases(v3.0.0)
Owner
Nutchaphon Rewik
iOS Engineer 🍎
Nutchaphon Rewik
A simple generator of PDF written in Swift.

Features | Requirements | Installation | Usage | Communication | LICENSE PDFGenerator PDFGenerator is a simple PDF generator that generates with UIVie

Suguru Kishimoto 712 Dec 29, 2022
An iOS PDF viewer and annotator written in Swift that can be embedded into any application.

Requirements iOS 9 or above Xcode 8 or above Swift 3.0 Note This project is still in early stages. Right now the PDF reader works both programmaticall

UXM Studio 269 Dec 11, 2022
PdfBuilder: a swift library made to make creation of the Pdf file from code simpler

PdfBuilder PdfBuilder is a swift library made to make creation of the Pdf file f

null 4 Jul 22, 2022
Draw Week Time Table on PDF using PDFKit in iOS Swift

DrawPDFTimeTable Draw Week Time Table on PDF using PDFKit in iOS Swift. Image Info This is the pdf of time table drawn using PDFKit in iOS Swift with

Kushagra Chandra 6 Nov 22, 2022
Swift package that uses WebKit to render PDF files from URLs

Swift package for generating a PDF file from a URL (rendered by WebKit)

aaronland 1 Feb 25, 2022
PLHKit: A Swift DSL for Rendering and creating PDF Files.

PLHKit PLH is a tribute to Portsaid Light House, Port Said Lighthouse was the first building in the world created with reinforced concrete. ?? PLHKit

null 10 Sep 2, 2022
PDF Reader Core for iOS

PDF Reader Core for iOS This project is no longer supported or maintained. It is only here for historical reasons. Please see the UXReader PDF Framewo

Julius Oklamcak 4.3k Jan 6, 2023
PDF generator using UIViews or UIViews with an associated XIB

Description Create UIView objects using any method you like, including interface builder with Auto-layout and size classes enabled. Then generate a PD

null 34 Dec 17, 2022
Generate beautiful .pdf Files from xib

Description The Library generates a PDF directly from interface builder with Auto-layouted views! Swift Version of UIView_2_PDF. Installation Download

Simon C. Krüger 16 Dec 17, 2022
TPPDF is a simple-to-use PDF builder for iOS

TPPDF is a fast PDF builder for iOS & macOS using simple commands to create advanced documents! Created and maintained by Philip Niedertscheider and a

techprimate 582 Jan 6, 2023
UIImage PDF extensions.

UIImagePlusPDF UIImage extensions to use PDF files. Using UIImagePlusPDF you can avoid a lot png images files (1x, 2x, 3x sizes) and simply replace ea

Dmytro Mishchenko 35 Jan 4, 2023
Estrutura Simples para Navegacao Web e Download PDF

Download-PDF-WebView Projeto desenvolvido em Swift com a função de criar uma estrutura simples para navegação Web em seu Aplicativo, permitindo a visu

Josué Rodrigues 1 Nov 30, 2021
Mephisto - A command line tool to convert Comic Book Zip archives to PDF and share them over AirDrop

mephisto A command line tool written in Swift to convert Comic Book Zip archives

null 0 Feb 7, 2022
Small utility to import PDF slides as vector images into Keynote for iOS.

Small utility to import PDF files into Keynote for iOS. This utility is especially helpful when presenting slideshows created by LaTeX

Luming Yin 6 Jun 14, 2022
TPPDF is a simple-to-use PDF builder for iOS

TPPDF is a fast PDF builder for iOS & macOS using simple commands to create advanced documents! Created and maintained by Philip Niedertscheider and a

techprimate 581 Dec 29, 2022
📚 A Swift ePub reader and parser framework for iOS.

FolioReaderKit is an ePub reader and parser framework for iOS written in Swift. Features ePub 2 and ePub 3 support Custom Fonts Custom Text Size Text

FolioReader 2.5k Jan 8, 2023
A Static Library to be embedded on iOS applications to display pdf documents derived from Fast PDF

FastPdfKit This repository contains the FastPdfKit iOS library with some sample projects. FastPdfKit is a library that let you show pdf documents in i

Dimension 1.2k Dec 22, 2022
A simple generator of PDF written in Swift.

Features | Requirements | Installation | Usage | Communication | LICENSE PDFGenerator PDFGenerator is a simple PDF generator that generates with UIVie

Suguru Kishimoto 712 Dec 29, 2022
An iOS PDF viewer and annotator written in Swift that can be embedded into any application.

Requirements iOS 9 or above Xcode 8 or above Swift 3.0 Note This project is still in early stages. Right now the PDF reader works both programmaticall

UXM Studio 269 Dec 11, 2022
RadialMenu is a custom control for providing a touch context menu (like iMessage recording in iOS 8) built with Swift & POP

RadialMenu Looking for help? For $150/hr I'll help with your RadialMenu problems including integrating it into your project. Email [email protected] t

Brad Jasper 297 Nov 27, 2022