Coder Social home page Coder Social logo

raybon-lee / uiimage-pdf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mindbrix/uiimage-pdf

0.0 2.0 0.0 2.14 MB

Simple UIImage PDF renderer category for iOS scalable assets

Home Page: http://blog.mindbrix.co.uk/2012/02/10/ios-scalable-assets/

Objective-C 100.00%

uiimage-pdf's Introduction

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" fitSize:CGSizeMake( 90, 50 ) ];
UIImage *img = [ UIImage imageWithPDFNamed:@"YingYang.pdf" atWidth:60 ];
UIImage *img = [ UIImage imageWithPDFNamed:@"YingYang.pdf" atHeight:90 ];
UIImage *img = [ UIImage originalSizeImageWithPDFNamed:@"YingYang.pdf" ];

UIImage *img = [ UIImage imageWithPDFURL:url atSize:CGSizeMake( 60, 60 ) atPage:1 ];

UIImage *img = [ UIImage imageWithPDFData:data atSize:CGSizeMake( 60, 60 ) atPage:1 ];

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

For a full API list consult the header file.

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

ARC

If your project doesn't use ARC: you must add the -fobjc-arc compiler flag to NSData+MD5.m, NSString+MD5.m, PDFView.m, UIImage+PDF.m and UIView+Image.m in Target Settings ==> Build Phases ==> Compile Sources.

Disk Cacheing

UIImage+PDF now transparently caches all rendered PDFs in <Application_Home>/Library/Caches/__PDF_CACHE__. This substantially improves application latency with large PDFs, especially on larger devices. To disable disk cacheing, call:

[ UIImage setShouldCacheOnDisk:NO ];

Memory Cacheing

UIImage+PDF can now use NSCache to cache rendered PDFs in memory. This feature is disabled by default. To enable it call:

[ UIImage setShouldCacheInMemory:YES ];

PDF file size

By default Adobe Illustrator saves exported PDFs very inefficiently. For best results, select File -> Save a Copy, select PDF format and then uncheck all the general options. Once you are ready to ship your app, run all your PDF assets through ShrinkIt (see below).

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.

Apps using UIImage+PDF

Here is a partial list of the apps using this category. If you want to add your app to this list, please submit a pull request.

Licence

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.

uiimage-pdf's People

Contributors

mindbrix avatar cescofry avatar mac-cain13 avatar chancancode avatar skela avatar wilkinsona avatar alloy avatar scottrhoyt avatar diederich avatar

Watchers

James Cloos avatar raybon.lee 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.