我要創造我用下面的代碼從瀏覽PDF我已經從網上得到了這一點,但如何調用該方法,並在那裏給的文件名創建PDF保存在文檔文件夾中。調用在iPhone應用程序中創建PDF方法也不工作
當我把這種方法它給發送異常無法識別的選擇。
[self createPDFfromUIView:someView saveToDcumentsWithFileName:@"my_pdf.pdf"];
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// 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, aView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:pdfContext];
// remove PDF rendering context
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
。例如createPDFfromUIView,它將從您要創建PDF的UIview對象和saveToDocumentsWithFileName告訴您,傳遞您想要的pdf文件的名稱。該文件將在Document目錄中創建。 – Swapnil
我這樣做給了異常,當我把這個方法說無法識別的選擇發送 – james
@EXC_BAD_ACCESS請如何我打電話的方法是正確與否 – james