Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从字符串创建PDF将创建空白屏幕_Ios_Cocoa Touch_Pdf_Quartz 2d - Fatal编程技术网

Ios 从字符串创建PDF将创建空白屏幕

Ios 从字符串创建PDF将创建空白屏幕,ios,cocoa-touch,pdf,quartz-2d,Ios,Cocoa Touch,Pdf,Quartz 2d,我正在尝试创建一个PDF文件,PDF的内容是存储在NSMutableString中的文本,该字符串存储在磁盘上。然而,出于某种原因,PDF文件是空白的。我已经检查了这段代码一段时间了,不明白为什么不使用字符串的内容创建PDF。我记录了字符串,文本肯定在那里。这是我正在使用的代码,存储数据的字符串是stringToSave: 如果有人能发现我哪里出了问题,并让我知道如何解决它,我将不胜感激。谢谢 编辑:我没有输入用于保存的代码,因为该部分工作正常。您发布的代码没有保存任何内容。您发布的代码使用了不

我正在尝试创建一个PDF文件,PDF的内容是存储在NSMutableString中的文本,该字符串存储在磁盘上。然而,出于某种原因,PDF文件是空白的。我已经检查了这段代码一段时间了,不明白为什么不使用字符串的内容创建PDF。我记录了字符串,文本肯定在那里。这是我正在使用的代码,存储数据的字符串是stringToSave:

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


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

您发布的代码没有保存任何内容。您发布的代码使用了不存在的变量myDictionary和stringToSave。发布的代码忽略了这个方法的两个参数。@rmaddy显然我不知道我在做什么,你能告诉我如何做到这一点吗?开始发布你的实际相关代码。当你有关于代码的问题时,你必须发布真实的代码,而不是类似的代码。
- (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();

}