【问题标题】:Export text or pdf导出文本或 pdf
【发布时间】:2012-11-16 11:33:46
【问题描述】:

在我的应用程序中,用户可以将一些信息添加到他的列表中,最后他想通过电子邮件将该列表发送给其他人。我只是想知道如何导出该列表?是否可以将其导出为 pdf 或 txt 文件?!

【问题讨论】:

    标签: ios xcode pdf text export


    【解决方案1】:

    如果您正在搜索 iOS5,请查看this Link

    http://www.raywenderlich.com/6581/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-1

    编辑:像这样使用UI elements

     [yourView.layer renderInContext:UIGraphicsGetCurrentContext()]
    

    【讨论】:

    • 感谢 Siba,我之前把那个教程发红了,我只是想知道是否可以使用我已经在我的 xib 文件中创建的当前 UILabel 或 UIView,而不是 NSString* textToDraw = @"Hello World "
    • stackoverflow.com/questions/9554670/… 这可能对你有帮助。
    【解决方案2】:

    好的,我使用了这段代码,不幸的是我丢失了找到答案的页面,很抱歉没有引用它。这是神奇的代码:

    -(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, mainView.bounds, nil);
        UIGraphicsBeginPDFPage();
        CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    
    
        // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
    
        [mainView.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);
    }
    

    【讨论】:

      猜你喜欢
      • 2022-10-12
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多