我想使用 CGPDF API 在 IPAD 上显示和操作 PDF,但首先,我试图以简单的方式在我的视图上显示 PDF(无需屏幕调整)。我不知道为什么我的应用程序中没有出现 PDF,也许我做错了。我正在使用 NSLOG 来计算页数,它确实有效,但 PDF 没有出现,只是在我的模拟器屏幕上出现白色背景。
这是我的代码:
//
**// ViewController.h**
// MeuCGPDF
//
// Created by admin on 01/11/13.
// Copyright (c) 2013 admin. All right reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
----------------------------------------------------------
//
**// ViewController.m**
// MeuCGPDF
//
// Created by admin on 01/11/13.
// Copyright (c) 2013 admin. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"livro" ofType:@"pdf"];
NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
size_t pageCount = CGPDFDocumentGetNumberOfPages(document);
CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawPDFPage(context, page);
NSLog(@"Paginas: %zu", pageCount);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
----------------------------------------------------------