結構前になりますが、PDFファイルの表示が出来るということで試した事があります。
一応PDFの表示をする事が出来ましたが、あまりPDFビューワぽくないので、他に良い方法があるように思います。
とりあえずメモ的に残しておきます。
// PDFを貼り付けるためのImageViewを作成 UIImageView *titleView = [self newPictureView:@"000.jpg"]; titleView.userInteractionEnabled = YES; titleView.backgroundColor = [UIColor whiteColor];
// PDFファイルの読み込み CFURLRef pdfURL; pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("t000.pdf"), NULL, NULL); pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); CFRelease(pdfURL);
// PDFファイルの画像を貼り付けるための白紙のコンテキストを作成 CGColorSpaceRef imageColorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef localContext; localContext = CGBitmapContextCreate(NULL, 320, 480, 8, 320 * 4, imageColorSpace, kCGImageAlphaPremultipliedLast);
// PDFのどのページを読み込むか指定 CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
// 描画時に使用する拡大縮小・移動用トランスフォームのインスタンス作成 CGAffineTransform pdfTransform;
CGContextSaveGState(localContext);
// スケーリング pdfTransform = CGAffineTransformMakeScale(10.0, 10.0); CGContextConcatCTM(localContext, pdfTransform); // 移動 pdfTransform = CGAffineTransformMakeTranslation(-30, -355); CGContextConcatCTM(localContext, pdfTransform); // PDF画像の縦横サイズの指定 pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, CGRectMake(0, 0, 320, 480), 0, TRUE); CGContextConcatCTM(localContext, pdfTransform); // 白紙のコンテキストにPDF画像を貼り付け CGContextDrawPDFPage(localContext, page);
CGContextRestoreGState(localContext);
// コンテキストからCGImageを作成 CGImageRef imgRef = CGBitmapContextCreateImage(localContext); // 画像の部分切り出し CGImageRef destImage; destImage = CGImageCreateWithImageInRect(imgRef, CGRectMake(0, 0, 220, 350));
// CGImageを元にUIImageを作成 UIImage *img = [[UIImage alloc] initWithCGImage:destImage]; // ImageViewに貼り付け [titleView setImage:img]; titleView.contentMode = UIViewContentModeTop;
// インスタンスの開放 [img release]; CGImageRelease(imgRef); CGImageRelease(destImage);
|
結構前の事なので、参考にしたのが何だったかはっきり覚えていませんが、たしかこのQuratzの本だったと思います。
洋書なので所々を翻訳サイトで翻訳しながら読んだような気がします。
Morgan Kaufmann Pub
発売日:2005-12-14
発送時期:在庫あり。
ランキング:60982
posted by ラキシス at 16:50
|
Comment(0)
|
TrackBack(0)
|
iPhoneプログラミング
|

|