CoreGraphicsを使用してPDFファイルをレンダリングするアプリケーションを開発しています。私は一度にPDFの1ページを表示しています。iPadでPDFを読み込むのが遅すぎる
NSString *pdfFullPath = [[NSBundle mainBundle] pathForResource:@"catalogue" ofType:@"pdf"];
pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:pdfFullPath]);
currentPage = [[_dataObject description] intValue];
[pdfView setImage:[self imageFromPDF:pdf withPageNumber:currentPage withScale:1.5]];
[_dataObject description]
を文字列として現在のページ番号が含まれています:viewDidLoad
で、私は次のコードを持っています。
その後、私はPDFをレンダリングするこの方法があります:
- (UIImage *)imageFromPDF:(CGPDFDocumentRef)_pdf withPageNumber:(NSUInteger)pageNumber withScale:(CGFloat)scale
{
if(pageNumber > 0 && pageNumber <= CGPDFDocumentGetNumberOfPages(_pdf))
{
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(_pdf, pageNumber);
CGRect tmpRect = CGPDFPageGetBoxRect(pdfPage,kCGPDFMediaBox);
CGRect rect = CGRectMake(tmpRect.origin.x, tmpRect.origin.y, tmpRect.size.width * scale, tmpRect.size.height * scale);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, scale, -scale);
CGContextDrawPDFPage(context, pdfPage);
UIImage *pdfImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return pdfImage;
}
return nil;
}
これはimageFromPDF
が呼び出されているので、私は最適化するために、どのような方法を探していたときに、完全にアプリケーションをロックし、非常に遅いプロセスであるように思わをそれで処理が速くなります。何か案は?