我制作了一个包含pdf文件的图书馆应用程序。 我使用fastpdfkit来阅读pdfs。
但是没有只发送一页pdf文件的解决方案。
是否可以通过电子邮件发送pdf文件的当前页面,而不是整个文档?。
答案 0 :(得分: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;
}