[Solved] Add a PDF from Internet(URL) to NSArray [closed]


Actually it’s not a good idea to store file contents for multiple PDF files into an array, as that would consume ways too much memory (and very likely the most of the time you don’t even need it).

It’s better to download the files to your app’s cache or documents folder and load/print files from there. Of course you can download files into memory, but this will definitely fail with big files.

So in the array you probably just want to have URL’s or filenames. Once you know which file you need, you actually load it (from your download location or from the URL) and do whatever you need to do with it.

However the answer to your question would be:

// CAUTION: This will block the thread while downloading
NSArray *items = [NSArray arrayWithObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.background.request.URL]]];

This statement will store the contents of the PDF file as NSData and put it in an array. To put more files in the array you can use [NSArray arrayWithObjects:..., nil].

1

solved Add a PDF from Internet(URL) to NSArray [closed]