Hi in my application I have to generate PDF file. That pdf file may include Images,Description,Numbers,border lines and page numbers.Can any one please let me know how to generate pdf file in ios.
Asked
Active
Viewed 1,557 times
1 Answers
4
Create your custom view to add image, tableview or anything. Points the pdf converter to the mutable data object and to the UIView to be converted to pdf.
Try this:
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData,self.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[self.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:@"ess.pdf"];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];

SampathKumar
- 2,525
- 8
- 47
- 82
-
Hi Thanks I tried it. But here I have one doubt that at this condition If (stringSize.height >= renderingRect.size.height) how can we split the text in two pages? Please can you share this code. – Naresh Nov 14 '13 at 05:54
-
-
Hi thanks for your reply. Actually I am facing an issue while spliting the text in two pages. I am unable to get any idea how to split the text in two pages. I am setting bottomline by getting text size and bottom line position. I am attaching the screen shot please check this and let me know the solution for this. – Naresh Nov 15 '13 at 05:52
-
Hi ios developer please check the attchment and help me to resolve my issue. – Naresh Nov 15 '13 at 05:58
-
-