0

我有一个将我的代码转换UIView为 pdf 的代码。现在我希望能够在UIActivityControllerFacebook 和 Twitter 集成中使用这个 PDF。我不知道该怎么做,但 PDF 的代码如下所示:

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];
    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories from the iOS device
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

如何初始化 PDF 以在 Facebook 和 Twitter 甚至电子邮件中发布?

4

1 回答 1

0

遗憾的是,您无法将 pdf 上传到 Facebook 和 Twitter。如果你有一个 FTP 服务器来上传它可能会是最好的。

你可以邮寄和打印,检查这个

    NSURL * url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: @ "data" ofType: @ "pdf"]];
    UIActivityViewController *act=[[UIActivityViewController alloc]initWithActivityItems:@[url] applicationActivities:nil];
    [self presentViewController:act animated:YES completion:nil];
于 2013-09-17T05:04:45.190 回答