【发布时间】:2012-02-25 18:15:37
【问题描述】:
我制作了一个包含 pdf 文件的库应用程序。 我使用 fastpdfkit 来阅读 pdf。
但是没有办法只发送一页pdf文件。
是否可以通过电子邮件发送 pdf 文件的当前页面,而不是整个文档?
【问题讨论】:
我制作了一个包含 pdf 文件的库应用程序。 我使用 fastpdfkit 来阅读 pdf。
但是没有办法只发送一页pdf文件。
是否可以通过电子邮件发送 pdf 文件的当前页面,而不是整个文档?
【问题讨论】:
如果你想要一张图片到 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;
}
【讨论】: