2012-02-25 6 views
0

私はpdfファイルを含むライブラリアプリを作った。 私はpdpdを読むためにfastpdfkitを使用しました。iOS上でPDF文書の現在のページをメールで送る方法

しかし、pdfファイルの1ページだけを送信するための解決策はありません。

文書全体ではなく、pdfファイルの現在のページをメールで送信できますか?

答えて

0

あなたが1ページにイメージをしたい場合は、この

UIImage *currentPage = [UIImage drawCurrentView:currentPageNum]; 

を使用することができますこれはdrawCurrentViewです:

+(UIImage*)drawCurrentView:(NSUInteger)currentPageNum 
{ 

NSString *filePath = //Your PDF Path 

CGSize resultImageSize = CGSizeMake(320, 480);//For iPhone 

CFStringRef pathRef = CFStringCreateWithCString (NULL, [filePath UTF8String], 
               kCFStringEncodingUTF8); 
CFURLRef pdfURL = CFURLCreateWithFileSystemPath (NULL, pathRef, 
               kCFURLPOSIXPathStyle, 0); 
CFRelease(pathRef); 
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(pdfURL); 

CFRelease(pdfURL); 
CGPDFPageRef myPageRef = CGPDFDocumentGetPage(pdf,currentPageNum); 

// get the rect of our page 
CGRect pageRect = CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox); 

// create a new context for resulting image of my desidered size 
UIGraphicsBeginImageContext(resultImageSize); 
CGContextRef ctx = UIGraphicsGetCurrentContext(); 
CGContextSaveGState(ctx); 
CGContextScaleCTM(ctx, 1, -1); 

// translate so the origin is offset by exactly the rect origin 
CGContextTranslateCTM(ctx, 0, -resultImageSize.height); 
CGContextScaleCTM(ctx, resultImageSize.width /pageRect.size.width,resultImageSize.height/ pageRect.size.height); 

// now draw the document 
CGContextDrawPDFPage(ctx, myPageRef); 
CGContextRestoreGState(ctx); 

// generate image 
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
CGPDFDocumentRelease(pdf); 

return resultingImage; 
} 
+0

drawCurrentViewは何ですか? UIImageのための方法はありません。 – fulberto100

+0

ああ、私はすべてのコードを過ぎていませんでした。私の編集を確認してください。 –

関連する問題