1

PDF のコンテンツが NSMutableString に格納されたテキストであり、文字列がディスクに格納されている PDF ファイルを作成しようとしています。ただし、何らかの理由で、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