【问题标题】:How to email current page of pdf document on iOS如何在 iOS 上通过电子邮件发送 pdf 文档的当前页面
【发布时间】:2012-02-25 18:15:37
【问题描述】:

我制作了一个包含 pdf 文件的库应用程序。 我使用 fastpdfkit 来阅读 pdf。

但是没有办法只发送一页pdf文件。

是否可以通过电子邮件发送 pdf 文件的当前页面,而不是整个文档?

【问题讨论】:

    标签: iphone ios ipad email pdf


    【解决方案1】:

    如果你想要一张图片到 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;
    }
    

    【讨论】:

    • 什么是drawCurrentView? UIImage 没有方法。
    • 哦,对不起@fulberto100 我没有通过所有代码..请检查我的编辑。
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2018-09-19
    • 2012-11-17
    • 1970-01-01
    • 2023-03-06
    • 2015-08-31
    • 1970-01-01
    相关资源
    最近更新 更多