Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-09-2010, 09:17 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
kieran12 is on a distinguished road
Default Load PDF from documents directory

Hi all,

I am using the 'Leaves' framework to add a page turn effect to my app. It displays PDF's using quartz and this works fine if you are loading a PDF from the main bundle. Here is the working code:

Code:
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("SampleIssue.pdf"), NULL, NULL);
		pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
		NSLog(@"PDF: %@", pdf);
		CFRelease(pdfURL);
I want to load a PDF from the documents directory though. Here is my code (which doesn't work):

Code:
// Get Documents Directory
		NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
		NSString *documentsDirectoryPath = [searchPaths objectAtIndex:0]; 
		NSString *tempPath = [documentsDirectoryPath stringByAppendingPathComponent:[appDelegate.issueToLoad stringByAppendingPathExtension:@"pdf"]];
		NSString *path = [tempPath stringByReplacingOccurrencesOfString:@"localhost/" withString:@""];
		NSLog(@"PATH: %@", path);
		
		//Display PDF
		CFURLRef pdfURL = CFURLCreateWithFileSystemPath (NULL, (CFStringRef)path, kCFURLPOSIXPathStyle, FALSE);
		NSLog(@"PDF URL: %@", pdfURL);
		pdf = CGPDFDocumentCreateWithURL(pdfURL);
		NSLog(@"PDF: %@", pdf);
My code gets the correct link to the file. However the final NSLog shows the 'pdf' is NULL. This is obviously a problem and the PDF doesn't load. Can anybody see any obvious problems with my code? Or do you know how I can accomplish this?

Thanks!
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 03-04-2011, 05:41 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
Jacos is on a distinguished road
Default Bump!

Did you get this to work?! Really need this.
Jacos is offline   Reply With Quote
Old 03-04-2011, 06:28 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
kieran12 is on a distinguished road
Default

Quote:
Originally Posted by Jacos View Post
Did you get this to work?! Really need this.
Ah, sorry I forgot to add the solution to the thread. Here is the code:

Code:
// Get Documents Directory
	NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
	NSString *documentsDirectoryPath = [searchPaths objectAtIndex:0]; 
	NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:[appDelegate.issueToLoad stringByAppendingPathExtension:@"pdf"]];
	
	NSFileManager *fileManager = [NSFileManager defaultManager];
	
	// Check if the file exists
	if ([fileManager fileExistsAtPath:path])
	{
		//Display PDF
		CFURLRef pdfURL = CFURLCreateWithFileSystemPath (NULL, (CFStringRef)path, kCFURLPOSIXPathStyle, FALSE);
		pdf = CGPDFDocumentCreateWithURL(pdfURL);
		leavesView.backgroundRendering = NO;
		CFRelease(pdfURL);
		[leavesView reloadData];
	}
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 03-06-2011, 11:13 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
Jacos is on a distinguished road
Default Didn't solve my problem :(

Hey, tried this for a couple of days now, it don't work. I tried to implement this in my PDF code.

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
    
	[scrollView removeFromSuperview];
	[myContentView removeFromSuperview];
	[tiledLayer removeFromSuperlayer];
	
	self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
	self.view.frame = CGRectMake(0, 0, 320, 411);
	
	myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL URLWithString:@"9A.pdf"]);
	NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"9A.pdf" withExtension:nil];
	myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
	myPageRef = CGPDFDocumentGetPage(myDocumentRef, 1);
	
	tiledLayer = [CATiledLayer layer];
	tiledLayer.delegate = self;
	tiledLayer.tileSize = CGSizeMake(320, 411);
	tiledLayer.levelsOfDetail = 100;
	tiledLayer.levelsOfDetailBias = 100           ;
	tiledLayer.frame = self.view.frame;
	
	myContentView = [[UIView alloc] init];
	myContentView.backgroundColor = [UIColor whiteColor];
	myContentView.frame =  CGRectMake(0, 0, 320, 411);
	
	[myContentView.layer addSublayer:tiledLayer];
	
	CGRect viewFrame =  CGRectMake(0, 0, 320, 411);
	viewFrame.origin = CGPointZero;
	
	scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
	scrollView.frame =  CGRectMake(0, 0, 320, 411);
	scrollView.delegate = self;
	scrollView.contentSize = self.view.frame.size;
	scrollView.maximumZoomScale = 5;
	[scrollView addSubview:myContentView];
	
	[self.view addSubview:scrollView];
	
}
Have you any idea how I could load an PDF from the documents dir with this code...?
Jacos is offline   Reply With Quote
Old 03-11-2011, 01:30 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
Jacos is on a distinguished road
Default Bump!

Hi, really would appreciate if you helped me out here!

Thanks in advance!

-----

Jacob L
Jacos is offline   Reply With Quote
Old 03-11-2011, 03:10 PM   #6 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Jacos,

You really need to start a new thread if you are not using Leaves. The answer to this thread has already been posted.
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 08-28-2011, 10:14 AM   #7 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 10
Emad Hegab is on a distinguished road
Default

can you please tell me where did you put the code.. i've put it in the viewWillAppear and it didn't work and it didn't work on init method in pdfviewcontroller either so where exactly did you put it ?
Emad Hegab is offline   Reply With Quote
Reply

Bookmarks

Tags
core graphics, pdf ipad webview cgpdf

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 343
10 members and 333 guests
alexP, gordo26, headkaze, mistergreen2011, nobstudio, Objective Zero, rayjeong, revg, Sloshmonster, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:15 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0