Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Which view you want to create as a pdf in that view do the following changes</p> <pre><code>NSString *fileName=@"PdfFromView.pdf"; [self createPDFfromUIView:self.view saveToDocumentsWithFileName:fileName]; -(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); </code></pre> <p>}</p> <p>After this code has been executed go to documents folder you will find the pdf document containing the same contents of that view you have passed in </p> <blockquote> <p>Blockquote</p> </blockquote> <p>[self createPDFfromUIView:<strong>self.view</strong> saveToDocumentsWithFileName:fileName]</p> <blockquote> <p>Blockquote</p> </blockquote> <p>this method call. this code working fine Thanks to Antonio</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload