• Stars
    star
    205
  • Rank 191,264 (Top 4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Objective-C PDF objects. Doing my part to help us stay out of the headache that is Core Foundation.

MTPDF

Objective-C PDF objects. Doing my part to help us stay out of the headache that is Core Foundation.

A Swift port

Installation

In your Podfile, add this line:

pod "MTPDF"

pod? => https://github.com/CocoaPods/CocoaPods/

NOTE: You may need to add -all_load to "Other Linker Flags" in your targets build settings if the pods library only contains categories.

Example Usage

Read a PDF from a file:

MTPDF *pdf = [MTPDF PDFWithContentsOfFile:path];
pdf.pages.count       // => 3
pdf.isEncrypted       // => NO
pdf.title             // => @"Forever Young"

Read a PDF from a URL:

MTPDF *pdf = [MTPDF PDFWithContentsOfURL:url];

Create a PDF from data:

MTPDF *pdf = [MTPDF PDFWithData:data];

Modify A PDF:

MTPDF *pdf = [MTPDF PDFWithContentsOfURL:url];
pdf.title   = @"New Title";
pdf.author  = @"New Author";
pdf.creator = @"New Creator";
pdf.subject = @"New Subject";

Write PDF to file:

[pdf writeToFile:file];

Iterate through pages:

for (MTPDFPage *page in pdf.pages) {
  page.size     // => (500, 600)
}

Draw a page in a UIView drawRect (fitting the height of the view):

MTPDFPage *page = pdf.pages[0];

// Calculate the size to draw based on the height of the view's rect
CGSize fullSize = page.size;
CGFloat ratio = fullSize.width / fullSize.height;
CGSize aspectFittingSize = CGSizeMake(rect.height * ratio, rect.height);

CGContextRef context = UIGraphicsGetCurrentContext();

[page drawInContext:context atSize:aspectFittingSize];

Draw a page to a CGPDFContext:

MTPDFPage *page = pdf.pages[0];
CGRect rect = page.frame;
CGContextRef PDFContext = CGPDFContextCreateWithURL((__bridge CFURLRef)([NSURL fileURLWithPath:destinationFilePath]), &rect, NULL);

[page drawInPDFContext:PDFContext];

CFRelease(PDFContext);

Export a page as an UIImage:

UIImage *img = [page imageWithPixelsPerPoint:4];

This allows you to export the PDF at whatever resolution you need. Keep in mind, whatever the pixels per point is, the width and height will grow by that factor from the original size.

More Repositories

1

MTMigration

Manages blocks of code that only need to run once on version updates in iOS apps.
Objective-C
913
star
2

MTAnimation

Animate UIView with 25+ timing functions. (Bounce, elastic, exponential, etc.)
Objective-C
505
star
3

MTDates

A thread safe date calculation library with all the date functions you'll ever need.
Objective-C
343
star
4

MTGeometry

An extension to Core Graphics Geometry. Intersections, scaling, etc.
Objective-C
212
star
5

MTStringAttributes

Easier way to create an attributes dictionary for NSAttributedString
Objective-C
154
star
6

MTControl

Attach block handlers to UIControl objects jQuery style
Objective-C
114
star
7

MTQueue

Add blocks to queues in a super terse and readable way!
Objective-C
61
star
8

MYSCategoryProperties

Quickly add properties to categories using runtime associations.
Objective-C
60
star
9

MTPencil

Draw animated lines (like an invisible pencil) with Core Graphics. (Prototype, will get much better).
Objective-C
47
star
10

MTFittedScrollView

A UIScrollView subclass that resizes itself to fit around its content.
Objective-C
39
star
11

MYSForms

Easy forms for iOS
Objective-C
33
star
12

MYSRuntime

Obj-C Library that makes runtime self-inspection and class modification dead easy.
Objective-C
33
star
13

MTColorDistance

A category on UIColor. Pass in an array of colors and it will return the closest color to the receiver.
Objective-C
24
star
14

MTPocket

Cocoa Web Requests
Objective-C
23
star
15

EKEventToiCal

Returns a string in iCal format for an EKEvent object
Objective-C
22
star
16

MTBlockAlertView

An iOS Alert View that uses block-based delegation instead of protocols.
Objective-C
22
star
17

FatSecretKit

iOS client library for the FatSecret API
Objective-C
21
star
18

MYSSharedSettings

Access local settings and settings shared via iCloud with properties.
Objective-C
20
star
19

MTDateComponentsPicker

A picker for choosing date components. Allows some components to be undefined.
Objective-C
15
star
20

FakeContacts

An XCode project you can build onto the simulator or device to generate any number or random contacts for app testing
Objective-C
13
star
21

MYSCoreText

An Objective-C wrapper around Apple's Core Text framework.
Objective-C
11
star
22

MYSDynamicAlertView

An alert view that uses UIKit Dynamics to present a fun/interactive way to respond to alerts.
Objective-C
9
star
23

flunk

A gem for testing Ruby on Rails web APIs by simulating a client.
Ruby
6
star
24

MYSShared

A submodule that includes objc code that will more than likely be used in any objc project we do.
Objective-C
3
star
25

MTTimer

An Objective-C timer that restricts firing to a time range. If it's called BEFORE min, it waits for min. If it's called AFTER max, it's called at max.
Objective-C
3
star
26

MYSGravityActionSheet

An action sheet that uses UIKit Dynamics to present buttons in a playful, interesting way.
Objective-C
2
star
27

MYSTableView

Objective-C
1
star
28

Pocket

A curl gem that doesn't suck
Ruby
1
star