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 02-17-2011, 06:36 PM   #1 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default PDF w/ CGPDF

Hey guys,

Im trying to display a pdf with CGPDF, but I cat get it to display.

My code is the same as Random-Ideas

Any help would be appreciated.

Thanks.
newDev is offline   Reply With Quote
Old 02-17-2011, 06:57 PM   #2 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

The code you linked to should work just fine. What does "I can't get it to display" mean?
JasonR is offline   Reply With Quote
Old 02-17-2011, 07:13 PM   #3 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

Sorry for being vague.

I ment that it wont call the function drawRect.
And there for wont display the PDF.
newDev is offline   Reply With Quote
Old 02-17-2011, 07:52 PM   #4 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

That's still pretty vague. I have no idea what you are trying to do. No one can help you until you explain what you are doing and what's failing.
JasonR is offline   Reply With Quote
Old 02-17-2011, 08:33 PM   #5 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

I just want to create a very simple PDF viewer, with one View that displays the first page of the PDF.

The Project is set up to be ViewBased app.

Im setting up the drawRect method in the PDFViewerVeiwController
is this right? or should it be in the PDFViewerAppDelegate?

I creating the file path in the viewdidload.

Let me know if that clears things up or if I still need more detail.

Thanks.
newDev is offline   Reply With Quote
Old 02-18-2011, 03:46 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you can user uiwebview.
__________________
dany_dev is offline   Reply With Quote
Old 02-18-2011, 04:46 PM   #7 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

I could use a WebView but the goal is to eventually add zooming and search functions.
newDev is offline   Reply With Quote
Old 02-18-2011, 06:22 PM   #8 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

If you want to do this with CGPDF functions, you need to read up on how to make a subclass of UIView. That's where you will put the drawRect function you were looking at. Between Apple's site, and Google, you should be able to find lot's of examples.
JasonR is offline   Reply With Quote
Old 02-18-2011, 10:25 PM   #9 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 23
harmar is on a distinguished road
Default

Quote:
Originally Posted by JasonR View Post
If you want to do this with CGPDF functions, you need to read up on how to make a subclass of UIView. That's where you will put the drawRect function you were looking at. Between Apple's site, and Google, you should be able to find lot's of examples.
check out this
https://github.com/vfr/Reader It uses CATiledLayer.
That is what I used as a basis for my PDF viewer app which I modified the code a bit to make it dual spread pages, page turning effect, etc
There is also Leaves, you can google for that.

Last edited by harmar; 02-18-2011 at 10:27 PM.
harmar is offline   Reply With Quote
Old 03-07-2011, 04:29 PM   #10 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

Haven't been able to reply to this in a while, neighbors got smart and put a password on there internet...

I subclassed the UIView and got the App to display the PDF.

Now my new questions is can I have the viewcontroller handle the subclassed uiview, instead of the appdelegate that is currently displaying the view.

Does that make scene?
Let me know if I need to clarify/ post code/etc.

Thanks.
newDev is offline   Reply With Quote
Old 03-08-2011, 02:01 PM   #11 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

No one?

Maybe this should be moved into the Advanced Forum?

A little help JasonR.

Thanks.
newDev is offline   Reply With Quote
Old 03-08-2011, 03:50 PM   #12 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

This doesn't sound advanced, and I have no idea what you are asking. Using a View Controller to control the view is the normal way. What are you doing?
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 03-08-2011, 11:19 PM   #13 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

Here is how im displaying the view with the AppDelegate:

AppDelegate.h
@class View;

@interface ......
...
View * theViewer;

Appdelegate.m
Code:
        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after application launch.
	CGRect wholeWindow = [window bounds];
	theViewer = [[View alloc] initWithFrame:wholeWindow];
	[theViewer setBackgroundColor:[UIColor clearColor]];

	
	// Add the view controller's view to the window and display.
    [window addSubview:theViewer];
    [window makeKeyAndVisible];

    return YES;
}
The viewcontroller is basically doing nothing right now.
The appdelegate is loading the view as a subview.

Sorry, I didnt mean to make it seem like this was an advanced topic, I was just getting frustrated that no one was helping.

Im going to fool around again with this tonight and will let you know how it goes tomorrow.

In the mean time please feel free to help me out and if i need to clarify please let me know.

Thanks
newDev is offline   Reply With Quote
Old 03-09-2011, 01:15 AM   #14 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Somehow you missed the basics of working with a view controller. The only place I know to tell you to look would be "Your First iOS Application" in the developers documentation that comes with XCode. It explains how to set up a simple app with a view controller.

Once you have a simple app with a viewcontroller, add a blank view in Interface Builder, and change the custom class to use the new subclass you just made.
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 03-09-2011, 08:53 AM   #15 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

I guess thats what i get for trolling the internet for an answer, i found it last night thanks for all the help.

If anyone needs help and wants some code snipitslet me know.

Thanks again!
newDev is offline   Reply With Quote
Old 03-09-2011, 09:44 AM   #16 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

since that this is a public forum, post the solution, i'm pretty sure that will be usefull to someone
__________________
dany_dev is offline   Reply With Quote
Old 03-09-2011, 10:00 PM   #17 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

View.h
Code:
 
#import <UIKit/UIKit.h>


@interface View : UIView {
	CGPDFDocumentRef document;
	int currentPage;
	UISwipeGestureRecognizer *swipeLeft, *swipeRight; 
}

@end
View.m
Code:
  #import "View.h"


@implementation View


- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
			
		swipeLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handelLeftSwipe:)];
		swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
		[self addGestureRecognizer:swipeLeft];
		[swipeLeft release];
		
		swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handelRightSwipe:)];
		swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
		[self addGestureRecognizer:swipeRight];
		[swipeRight release];
		
			// Initialization code
		NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"BabyNMeapp" ofType:@"pdf"];
		NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
		document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
		
		currentPage = 1;
    }
    return self;
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
	[super touchesEnded:touches withEvent:event];

    UITouch *touch = [touches anyObject];

	if ([touch tapCount] == 2) {
		UIAlertView *alert=[[[UIAlertView alloc] initWithTitle:@"Two Taps" message:@"you tapped twice" delegate:self cancelButtonTitle:@"Yes I did" otherButtonTitles:nil] autorelease];
		[alert show];
		
	}
}



-(void)handelLeftSwipe:(UISwipeGestureRecognizer *)recognizer {
	currentPage++;
	NSLog(@"Swipe");
	[self setNeedsDisplay];
	if (currentPage > 4) {
		currentPage = 1;
	}
}

-(void)handelRightSwipe:(UISwipeGestureRecognizer *)recognizer {
	currentPage--;
	NSLog(@"SwipeLeft");
	[self setNeedsDisplay];
	if (currentPage < 1) {
		currentPage = 4;
	}
}

 // Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
	if(document)
    {
        CGPDFPageRef page = CGPDFDocumentGetPage(document, currentPage);
		
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        
        CGContextSaveGState(ctx);
        
        CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
        CGContextScaleCTM(ctx, 1.0, -1.0);
        CGContextConcatCTM(ctx, 
						   CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, 
														[self bounds], 0, true));
        
        CGContextDrawPDFPage(ctx, page);    
        CGContextRestoreGState(ctx);
    }
}


- (void)dealloc {
    [super dealloc];
}


@end
newDev is offline   Reply With Quote
Old 03-09-2011, 10:02 PM   #18 (permalink)
Registered Member
 
newDev's Avatar
 
Join Date: Jul 2010
Location: Utah
Posts: 75
newDev is on a distinguished road
Default

PDFViewerVeiwController.h
Code:
#import <UIKit/UIKit.h>

@interface PDFViewerViewController : UIViewController {

}
@end

PDFViewerVeiwController.m
Code:
#import "PDFViewerViewController.h"
#import "PDFViewerAppDelegate.h"

@implementation PDFViewerViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
    if ((self = [super initWithNibName:nibName bundle:nibBundle])) {
        // Custom initialization

	}
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];
	self.wantsFullScreenLayout = YES;
	
	View *myView = [[View alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
	self.view = myView;
	[self.view setBackgroundColor:[UIColor clearColor]];
	
	[myView release];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
newDev is offline   Reply With Quote
Reply

Bookmarks

Tags
cgpdf, pdf, pdf view

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: 369
13 members and 356 guests
cpsclicker, dre, Error404, Gaz, gmarro, jeroenkeij, Kirkout, Music Man, PavelMik, teebee74, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

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