Skip to content
This repository

Simple UIImage PDF renderer category for iOS scalable assets

tree: 86d17c89e3

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 Classes
Octocat-spinner-32 UIImage+PDF example.xcodeproj
Octocat-spinner-32 UIImage+PDF
Octocat-spinner-32 .gitignore Tweaked .gitignore March 02, 2012
Octocat-spinner-32 MainWindow.xib First release October 16, 2011
Octocat-spinner-32 README.md
Octocat-spinner-32 UIImage_PDF_example-Info.plist
Octocat-spinner-32 UIImage_PDF_exampleViewController.xib First release October 16, 2011
Octocat-spinner-32 UIImage_PDF_example_Prefix.pch First release October 16, 2011
Octocat-spinner-32 YingYang.pdf First release October 16, 2011
Octocat-spinner-32 main.m First release October 16, 2011
README.md

UIImage+PDF

UIImage+PDF provides a UIImage class category method to render a UIImage from any PDF stored in the application bundle. The motivation for this was to enable the easy use of scaleable vector assets in iOS apps.

Usage

Add the sources files in the UIImage+PDF sub folder to your project. Use the following line to import the necessary methods.

#import "UIImage+PDF.h"

Then simply call one of the UIImage class methods as shown here:

UIImage *img = [ UIImage imageWithPDFNamed:@"YingYang.pdf" atSize:CGSizeMake( 40, 40 ) ];
UIImage *img = [ UIImage imageWithPDFNamed:@"YingYang.pdf" atWidth:60 ];
UIImage *img = [ UIImage imageWithPDFNamed:@"YingYang.pdf" atHeight:90 ];
UIImage *img = [ UIImage originalSizeImageWithPDFNamed:@"YingYang.pdf" ];

The atWidth: and atHeight: methods are particularly useful as they preserve the aspect ratio of the source PDF.

An example project is included in this repository. The important code is in viewDidLoad: in UIImage_PDF_exampleViewController.m.

PDF file size

By default Adobe Illustrator saves exported PDFs very inefficiently. For best results, export in EPS format, load this into Preview and then save as a PDF. The included example file YingYang.pdf shrunk to 10% of its original size with this workflow.

Other vector graphics editors which natively use the OSX Quartz renderer, such as Sketch, will create much more compact PDFs.

The amazing devs at Panic have now released a PDF shrinking utility, ShrinkIt, which should take a lot of the pain out of a vector asset workflow.

Licence

This licence is derived from one used by Matt Gallagher

Copyright 2012 Nigel Timothy Barber - @mindbrix. All rights reserved.

Permission is given to use this source code file without charge in any project, commercial or otherwise, entirely at your risk, with the condition that any redistribution (in part or whole) of source code must retain this copyright and permission notice. Attribution in compiled projects is appreciated but not required.

Further Reading

Matt Gemmell has an excellent article on his blog explaining how to use PDF images in iOS apps.

Something went wrong with that request. Please try again.