Put PDF into NSData

后端 未结 1 1182
挽巷
挽巷 2021-01-03 00:14

How do I put my PDF into NSData? I have the location of the PDF as a string in my Documents Directory of the app. When I try to email it, I see the PDF in the

相关标签:
1条回答
  • 2021-01-03 00:49

    Based on how the pdfName variable is being set, it looks like your "title" value does not include the PDF suffix. Have you tried:

    NSString *documentsDirectory = [self GetURLForPDF]; // I know this name is bad since it is really a NSString
    NSLog(@"DocumentsDirectory: %@", documentsDirectory);
    NSString *fullTitle = [NSString stringWithFormat:@"%@.pdf", title];
    NSString *pdfName = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fullTitle];
    NSLog(@"pdfName: %@", pdfName);
    NSData *pdfData = [NSData dataWithContentsOfFile:pdfName];
    [mailComposer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:fullTitle];    
    [self presentModalViewController:mailComposer animated:YES];
    
    0 讨论(0)
提交回复
热议问题