Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ An example project is included in this repository. The important code is in `vie
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._
_**If your project doesn't use ARC**: you must add the `-fobjc-arc` compiler flag to `NSData+MD5.m`, `NSString+MD5.m`, `NTBPDFView.m`, `UIImage+PDF.m` and `UIView+Image.m` in Target Settings ==> Build Phases ==> Compile Sources._


Disk Cacheing
Expand Down
12 changes: 6 additions & 6 deletions UIImage+PDF example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; };
28D7ACF80DDB3853001CB0EB /* UIImage_PDF_exampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* UIImage_PDF_exampleViewController.m */; };
A60041BF1779A5C500128861 /* NSData+MD5.m in Sources */ = {isa = PBXBuildFile; fileRef = A60041BE1779A5C500128861 /* NSData+MD5.m */; };
A6685B1D1449C642006A3A42 /* PDFView.m in Sources */ = {isa = PBXBuildFile; fileRef = A6685B181449C642006A3A42 /* PDFView.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
A6685B1D1449C642006A3A42 /* NTBPDFView.m in Sources */ = {isa = PBXBuildFile; fileRef = A6685B181449C642006A3A42 /* NTBPDFView.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
A6685B1E1449C642006A3A42 /* UIImage+PDF.m in Sources */ = {isa = PBXBuildFile; fileRef = A6685B1A1449C642006A3A42 /* UIImage+PDF.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
A6685B1F1449C642006A3A42 /* UIView+Image.m in Sources */ = {isa = PBXBuildFile; fileRef = A6685B1C1449C642006A3A42 /* UIView+Image.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
A6CF4D5F15384D12000AA6BB /* NSString+MD5.m in Sources */ = {isa = PBXBuildFile; fileRef = A6CF4D5E15384D12000AA6BB /* NSString+MD5.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
Expand All @@ -41,8 +41,8 @@
8D1107310486CEB800E47090 /* UIImage_PDF_example-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "UIImage_PDF_example-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
A60041BD1779A5C500128861 /* NSData+MD5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+MD5.h"; sourceTree = "<group>"; };
A60041BE1779A5C500128861 /* NSData+MD5.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+MD5.m"; sourceTree = "<group>"; };
A6685B171449C642006A3A42 /* PDFView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFView.h; sourceTree = "<group>"; };
A6685B181449C642006A3A42 /* PDFView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PDFView.m; sourceTree = "<group>"; };
A6685B171449C642006A3A42 /* NTBPDFView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NTBPDFView.h; sourceTree = "<group>"; };
A6685B181449C642006A3A42 /* NTBPDFView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTBPDFView.m; sourceTree = "<group>"; };
A6685B191449C642006A3A42 /* UIImage+PDF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+PDF.h"; sourceTree = "<group>"; };
A6685B1A1449C642006A3A42 /* UIImage+PDF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+PDF.m"; sourceTree = "<group>"; };
A6685B1B1449C642006A3A42 /* UIView+Image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Image.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -139,8 +139,8 @@
A60041BE1779A5C500128861 /* NSData+MD5.m */,
A6CF4D5D15384D12000AA6BB /* NSString+MD5.h */,
A6CF4D5E15384D12000AA6BB /* NSString+MD5.m */,
A6685B171449C642006A3A42 /* PDFView.h */,
A6685B181449C642006A3A42 /* PDFView.m */,
A6685B171449C642006A3A42 /* NTBPDFView.h */,
A6685B181449C642006A3A42 /* NTBPDFView.m */,
A6685B191449C642006A3A42 /* UIImage+PDF.h */,
A6685B1A1449C642006A3A42 /* UIImage+PDF.m */,
A6685B1B1449C642006A3A42 /* UIView+Image.h */,
Expand Down Expand Up @@ -227,7 +227,7 @@
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
1D3623260D0F684500981E51 /* UIImage_PDF_exampleAppDelegate.m in Sources */,
28D7ACF80DDB3853001CB0EB /* UIImage_PDF_exampleViewController.m in Sources */,
A6685B1D1449C642006A3A42 /* PDFView.m in Sources */,
A6685B1D1449C642006A3A42 /* NTBPDFView.m in Sources */,
A6685B1E1449C642006A3A42 /* UIImage+PDF.m in Sources */,
A6685B1F1449C642006A3A42 /* UIView+Image.m in Sources */,
A6CF4D5F15384D12000AA6BB /* NSString+MD5.m in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions UIImage+PDF/PDFView.h → UIImage+PDF/NTBPDFView.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// PDFView.h
// NTBPDFView.h
//
// Created by Nigel Barber on 15/10/2011.
// Copyright 2011 Mindbrix Limited. All rights reserved.
Expand All @@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>


@interface PDFView : UIView
@interface NTBPDFView : UIView
{

}
Expand Down
10 changes: 5 additions & 5 deletions UIImage+PDF/PDFView.m → UIImage+PDF/NTBPDFView.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// PDFView.m
// NTBPDFView.m
//
// Created by Nigel Barber on 15/10/2011.
// Copyright 2011 Mindbrix Limited. All rights reserved.
//

#import "PDFView.h"
#import "NTBPDFView.h"


@implementation PDFView
@implementation NTBPDFView

@synthesize page = m_page;
@synthesize resourceName = m_resourceName;
Expand All @@ -33,7 +33,7 @@ -(void)setResourceName:(NSString *)resourceName
{
m_resourceName = resourceName;

self.resourceURL = [ PDFView resourceURLForName: self.resourceName ];
self.resourceURL = [ NTBPDFView resourceURLForName: self.resourceName ];
}


Expand All @@ -54,7 +54,7 @@ -(void)setResourceData:(NSData *)data

+(CGRect) mediaRect:(NSString *)resourceName
{
return [ PDFView mediaRectForURL:[ PDFView resourceURLForName: resourceName ]];
return [ NTBPDFView mediaRectForURL:[ NTBPDFView resourceURLForName: resourceName ]];
}


Expand Down
2 changes: 1 addition & 1 deletion UIImage+PDF/UIImage+PDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import <UIKit/UIKit.h>
#import "UIView+Image.h"
#import "PDFView.h"
#import "NTBPDFView.h"
#import "NSData+MD5.h"
#import "NSString+MD5.h"

Expand Down
36 changes: 18 additions & 18 deletions UIImage+PDF/UIImage+PDF.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,60 +123,60 @@ +(NSString *)cacheFilenameForURL:(NSURL *)resourceURL atSize:(CGSize)size atScal

+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atSize:(CGSize)size atPage:(NSUInteger)page
{
return [ self imageWithPDFURL:[ PDFView resourceURLForName:resourceName ] atSize:size atPage:page ];
return [ self imageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName ] atSize:size atPage:page ];
}

+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atSize:(CGSize)size
{
return [ self imageWithPDFURL:[ PDFView resourceURLForName:resourceName ] atSize:size ];
return [ self imageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName ] atSize:size ];
}

+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atWidth:(CGFloat)width atPage:(NSUInteger)page
{
return [ self imageWithPDFURL:[ PDFView resourceURLForName:resourceName ] atWidth:width atPage:page ];
return [ self imageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName ] atWidth:width atPage:page ];
}

+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atWidth:(CGFloat)width
{
return [ self imageWithPDFURL:[ PDFView resourceURLForName:resourceName ] atWidth:width ];
return [ self imageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName ] atWidth:width ];
}

+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atHeight:(CGFloat)height atPage:(NSUInteger)page
{
return [ self imageWithPDFURL:[ PDFView resourceURLForName:resourceName ] atHeight:height atPage:page ];
return [ self imageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName ] atHeight:height atPage:page ];
}

+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atHeight:(CGFloat)height
{
return [ self imageWithPDFURL:[ PDFView resourceURLForName:resourceName ] atHeight:height ];
return [ self imageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName ] atHeight:height ];
}

+(UIImage *) imageWithPDFNamed:(NSString *)resourceName fitSize:(CGSize)size atPage:(NSUInteger)page
{
return [ self imageWithPDFURL:[ PDFView resourceURLForName:resourceName] fitSize:size atPage:page ];
return [ self imageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName] fitSize:size atPage:page ];
}

+(UIImage *) imageWithPDFNamed:(NSString *)resourceName fitSize:(CGSize)size
{
return [ self imageWithPDFURL:[ PDFView resourceURLForName:resourceName] fitSize:size ];
return [ self imageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName] fitSize:size ];
}

+(UIImage *) originalSizeImageWithPDFNamed:(NSString *)resourceName atPage:(NSUInteger)page
{
return [ self originalSizeImageWithPDFURL:[ PDFView resourceURLForName:resourceName ] atPage:page ];
return [ self originalSizeImageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName ] atPage:page ];
}

+(UIImage *) originalSizeImageWithPDFNamed:(NSString *)resourceName
{
return [ self originalSizeImageWithPDFURL:[ PDFView resourceURLForName:resourceName ]];
return [ self originalSizeImageWithPDFURL:[ NTBPDFView resourceURLForName:resourceName ]];
}


#pragma mark - Resource Data

+(UIImage *) originalSizeImageWithPDFData:(NSData *)data
{
CGRect mediaRect = [ PDFView mediaRectForData:data atPage:1 ];
CGRect mediaRect = [ NTBPDFView mediaRectForData:data atPage:1 ];

return [ UIImage imageWithPDFData:data atSize:mediaRect.size atPage:1 ];
}
Expand All @@ -191,7 +191,7 @@ +(UIImage *)imageWithPDFData:(NSData *)data atWidth:(CGFloat)width atPage:(NSUIn
if ( data == nil )
return nil;

CGRect mediaRect = [ PDFView mediaRectForData:data atPage:page ];
CGRect mediaRect = [ NTBPDFView mediaRectForData:data atPage:page ];
CGFloat aspectRatio = mediaRect.size.width / mediaRect.size.height;
CGSize size = CGSizeMake( width, ceil( width / aspectRatio ));

Expand All @@ -208,7 +208,7 @@ +(UIImage *)imageWithPDFData:(NSData *)data atHeight:(CGFloat)height atPage:(NSU
if ( data == nil )
return nil;

CGRect mediaRect = [ PDFView mediaRectForData:data atPage:page ];
CGRect mediaRect = [ NTBPDFView mediaRectForData:data atPage:page ];
CGFloat aspectRatio = mediaRect.size.width / mediaRect.size.height;
CGSize size = CGSizeMake( ceil( height * aspectRatio ), height );

Expand Down Expand Up @@ -254,7 +254,7 @@ +(UIImage *)imageWithPDFData:(NSData *)data atSize:(CGSize)size atPage:(NSUInteg
CGContextRef ctx = CGBitmapContextCreate(NULL, size.width * screenScale, size.height * screenScale, 8, 0, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
CGContextScaleCTM(ctx, screenScale, screenScale);

[PDFView renderIntoContext:ctx url:nil data:data size:size page:page preserveAspectRatio:preserveAspectRatio];
[NTBPDFView renderIntoContext:ctx url:nil data:data size:size page:page preserveAspectRatio:preserveAspectRatio];
CGImageRef image = CGBitmapContextCreateImage(ctx);
pdfImage = [[UIImage alloc] initWithCGImage:image scale:screenScale orientation:UIImageOrientationUp];

Expand Down Expand Up @@ -308,7 +308,7 @@ +(UIImage *) imageWithPDFURL:(NSURL *)URL atSize:(CGSize)size atPage:(NSUInteger
CGContextRef ctx = CGBitmapContextCreate(NULL, size.width * screenScale, size.height * screenScale, 8, 0, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
CGContextScaleCTM(ctx, screenScale, screenScale);

[PDFView renderIntoContext:ctx url:URL data:nil size:size page:page preserveAspectRatio:preserveAspectRatio];
[NTBPDFView renderIntoContext:ctx url:URL data:nil size:size page:page preserveAspectRatio:preserveAspectRatio];
CGImageRef image = CGBitmapContextCreateImage(ctx);
pdfImage = [[UIImage alloc] initWithCGImage:image scale:screenScale orientation:UIImageOrientationUp];

Expand Down Expand Up @@ -350,7 +350,7 @@ +(UIImage *) imageWithPDFURL:(NSURL *)URL fitSize:(CGSize)size

+(UIImage *) imageWithPDFURL:(NSURL *)URL atWidth:(CGFloat)width atPage:(NSUInteger)page
{
CGRect mediaRect = [ PDFView mediaRectForURL:URL atPage:page ];
CGRect mediaRect = [ NTBPDFView mediaRectForURL:URL atPage:page ];
CGFloat aspectRatio = mediaRect.size.width / mediaRect.size.height;

CGSize size = CGSizeMake( width, ceil( width / aspectRatio ));
Expand All @@ -369,7 +369,7 @@ +(UIImage *) imageWithPDFURL:(NSURL *)URL atHeight:(CGFloat)height atPage:(NSUIn
if ( URL == nil )
return nil;

CGRect mediaRect = [ PDFView mediaRectForURL:URL atPage:page ];
CGRect mediaRect = [ NTBPDFView mediaRectForURL:URL atPage:page ];
CGFloat aspectRatio = mediaRect.size.width / mediaRect.size.height;

CGSize size = CGSizeMake( ceil( height * aspectRatio ), height );
Expand All @@ -387,7 +387,7 @@ +(UIImage *) originalSizeImageWithPDFURL:(NSURL *)URL atPage:(NSUInteger)page
if ( URL == nil )
return nil;

CGRect mediaRect = [ PDFView mediaRectForURL:URL atPage:page];
CGRect mediaRect = [ NTBPDFView mediaRectForURL:URL atPage:page];

return [ UIImage imageWithPDFURL:URL atSize:mediaRect.size atPage:page preserveAspectRatio:YES ];
}
Expand Down