1

我正在尝试创建一个 PDF 文件,PDF 的内容是存储在 NSMutableString 中的文本,并且该字符串存储在磁盘上。但由于某种原因,PDF 出现空白。我已经检查了这段代码一段时间,无法弄清楚为什么没有使用字符串的内容创建 PDF。我 NSLogged 字符串,文本肯定在那里。这是我正在使用的代码,存储数据的字符串是stringToSave

- (void)createPDFfromString:(NSMutableString*)string saveToDocumentsWithFileName:(NSString*)aFilename
{
     CGRect stringRect = [[UIScreen mainScreen] bounds];

    // 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, stringRect, myDictionary);
    UIGraphicsBeginPDFPage();

    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


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

    UIFont *theFont = [UIFont systemFontOfSize:12];

    [stringToSave drawInRect:stringRect withFont:theFont]; 

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

}

如果有人能发现我哪里出了问题并让我知道如何解决它,将不胜感激。谢谢!

编辑:我没有输入我用来保存的代码,因为那部分工作正常。

4

0 回答 0