Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to convert a NSData to pdf in iPhone sdk?
- NSString *string=[NSString stringWithFormat:@"%@.pdf",[chapersArray objectAtIndex:pageIndex]];
- [controller1 addAttachmentData:pdfData mimeType:@"application/pdf" fileName:string];
- [self presentModalViewController:controller1 animated:YES];
- [controller1 release];
- //to convert pdf to NSData
- NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"test.pdf"];
- NSData *myData = [NSData dataWithContentsOfFile:pdfPath];
- //to convert NSData to pdf
- NSData *data = //some nsdata
- CFDataRef myPDFData = (CFDataRef)data;
- CGDataProviderRef provider = CGDataProviderCreateWithCFData(myPDFData);
- CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(provider);
- -(IBAction)saveasPDF:(id)sender{
- NSString *string=[NSString stringWithFormat:@"%@.pdf",[chapersArray objectAtIndex:pageIndex]];
- [controller1 addAttachmentData:pdfData mimeType:@"application/pdf" fileName:string];
- [self presentModalViewController:controller1 animated:YES];
- [pdfData writeToFile:[self getDBPathPDf:string] atomically:YES];
- }
- -(NSString *) getDBPathPDf:(NSString *)PdfName {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
- NSString *documentsDir = [paths objectAtIndex:0];
- return [documentsDir stringByAppendingPathComponent:PdfName];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement