長いHTMLページがあり、それを複数ページのPDFファイルに変換したいと思いました。
私はアップルとここで提供されている指示に従いまし た-与えられた文字列コンテンツに対してマルチページPDFを作成する方法。
ただし、NSStringのフォーマット(データのようなものを使用)は、htmlページを作成するよりも困難です。このhtmlを作成し、UIWebViewに表示しました。
ここで、このHTMLからマルチページPDFファイルにPDFを作成したいと思います。
私が使用しているコードは、単一のPDFを作成できます。
-(void)createPDFfromUIView:(UIWebView *)aView saveToDocumentsWithFileName:(NSString *)aFilename
{{
//バイト配列などのバイナリデータで更新するための可変データオブジェクトを作成します
NSMutableData * pdfData=[NSMutableDataデータ];
//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:documentDirectoryFilenameatomically:YES];
NSLog(@ "documentDirectoryFileName:%@"、documentDirectoryFilename);
}
誰か助けてもらえますか?