Xcode - 基于照片的PDF生成时间

时间:2015-05-08 00:41:16

标签: ios objective-c pdf-generation

我开发了一个应用程序,可以从照片库中的图像生成PDF报告,然后通过电子邮件发送PDF。问题我发现PDF需要一些时间来生成,如果用户过快地点击发送按钮,那么发送的电子邮件不会附加文件。如果PDF准备就绪,最简单/最好的方法是什么?或者我应该采取最坏的情况(30张)测试生成PDF并使用该时间所需的时间?

- (IBAction)generatePDFbutton:(id)sender {
//generates the pdf
[self generatePdf:pdfPathWithFileName];
// attaches the pdf to email and opens mail view
mailComposer  = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = (id)self;
[mailComposer setModalPresentationStyle:UIModalPresentationFormSheet];
[mailComposer setSubject:pdfTitle];
[mailComposer addAttachmentData:pdfLoc mimeType:@"application/pdf" fileName:pdfName];
[self presentViewController:mailComposer animated:YES completion:NULL];

提前致谢

-(void)generatePdf:(NSString *)filePath{
UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
// checks the # of photos and calculates the # of pages needed
int pageNum = ceil(self.assets.count/6) + 1;
NSUInteger imageSelect = 0;
// starts first page at the 2nd coordinate
NSUInteger rectCo = 2;
for (int pageCount = 0; pageCount < pageNum; pageCount++){
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 850, 1100), nil);
    [self drawBackground];
    [self drawHeader2];
    if (pageCount == 0){
        [self drawHeader];
        [self drawData];
    }
    [self drawPageNums:pageCount+1];
    if ([self.assets count]) {
        if (pageCount != 0){
            rectCo = 0;
        }
        for (rectCo; rectCo < 6; rectCo++){
            if (imageSelect == self.assets.count){
                break;
            }
            [self drawImages:rectCo :imageSelect];
            imageSelect++;
        }
    }
}
UIGraphicsEndPDFContext();}

这是pdfLoc代码:(pdfData == pdfLoc):

mainString = [NSString stringWithFormat:@"%@%@", mainString, @".pdf"];
pagesize = CGSizeMake(850, 1100);
NSString *filename = [dateString stringByAppendingString:@".pdf"];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *pdfPathWithFileName = [documentDirectory stringByAppendingPathComponent:mainString];
NSData *pdfData = [NSData dataWithContentsOfFile:pdfPathWithFileName];

[self generatePdf:pdfPathWithFileName];
[self mailCompose:pdfData:filename];}

0 个答案:

没有答案