Hey, I have a code for viewing, scrolling and zooming. But now the PDF loads from the application bundle. How could I load it from the documents directory?
Here is my code in the ViewDidLoad: method:
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];
}
All answers is appreciated and thanks in advance!
-----
Jacob L