iosuiimageviewcore-animationcatiledlayer

Programatically save a PDF in the iPhone


I'm getting a PDF file in my app like this :

NSURL* pdfURL = [NSURL URLWithString:urlStr];
CGPDFDocumentRef PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfURL);
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);

I know that for the images, we can use this method in order to save it in the iPhone :

[UIImagePNGRepresentation(image) writeToFile:uniquePath atomically:YES];

But is there a way to write/save the PDF file in the iPhone programatically ?


Solution

  • Here's one easy way:

    NSData *myFile = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"your_url"]]; 
    [myFile writeToFile:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"yourfilename.pdf"] atomically:YES];