Document Downloads

PSPDFKit usually works best with PDF documents on the local file system of your device. There are several reasons advocating for using local file system documents (performance, cache control, battery impact, ...).

If you have a PDF document that is not on the local filesystem, you can use URLSession to download the PDF and display it using PSPDFViewController.

Create a URLSession object with the required configurations. Then, use the session to create a download task (URLSessionDownloadTask) with the remote URL of the PDF document. Before resuming the task make sure you have set the session object's delegate.

funcurlSession(_session:URLSession,downloadTask:URLSessionDownloadTask,didFinishDownloadingTolocation:URL){do{// destinationFileURL is the desired location of the file to save which shall be used by PSPDFViewController.tryFileManager.default.moveItem(at:location,to:destinationFileURL)}catch{print(error)}}

-(void)URLSession:(NSURLSession*)sessiondownloadTask:(NSURLSessionDownloadTask*)downloadTaskdidFinishDownloadingToURL:(NSURL*)location{NSError*error;// destinationFileURL is the desired location of the file to save which shall be used by PSPDFViewController.[[NSFileManagerdefaultManager]moveItemAtURL:locationtoURL:destinationFileURLerror:&error];if(error){NSLog(@"%@",error.localizedDescription);}}

Take a look at DocumentProgressExample.swift in the PSPDFCatalog for a complete example.