私は円グラフを作成したiphoneアプリを持っています。グラフをiphoneのpdfファイルに保存する必要があります。
以下は PieChart のコードですが、どうすればそれを pdf に保存できますか? テキストを pdf に保存できることを読みましたが、これを保存する方法
-(void)createGraph{
PieClass *myPieClass=[[PieClass alloc]initWithFrame:CGRectMake(400,40, 320, 230)];
myPieClass.itemArray=[[NSArray alloc]initWithObjects:textFieldOne.text,textFieldTwo.text,textFieldThree.text, nil];
myPieClass.myColorArray=[[NSArray alloc]initWithObjects:[UIColor purpleColor],[UIColor redColor],[UIColor orangeColor], nil];
myPieClass.radius=100;
[self.view addSubview:myPieClass];
[self creatPDFFromView:@"mydata.pdf"];
}
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// バイト配列などのバイナリ データで更新する可変データ オブジェクトを作成します
NSMutableData *pdfData = [NSMutableData data];
// PDF コンバーターを変更可能なデータ オブジェクトと変換対象の UIView にポイントします
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// ビューに rect を描画するため、これは UIGraphicsBeginPDFContextToData によってキャプチャされます
[aView.layer renderInContext:pdfContext];
// PDF レンダリング コンテキストを削除します
UIGraphicsEndPDFContext();
// iOS デバイスからドキュメント ディレクトリを取得します
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// ミュータブル データ オブジェクトにそのコンテキストをディスク上のファイルに書き込むように指示します
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}