objective-cpspdfkit

PSPDFKit taking long time to give error `documentRef is nil , cannot get pageRef`


I have used this code :

NSURL *documentURL= [NSURL fileURLWithPath:aStrPrintPdfPath isDirectory:NO];
PSPDFDocument *document = [PSPDFDocument documentWithURL:documentURL];

PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document];
pdfController.pageTransition = PSPDFPageTransitionCurl;
pdfController.renderingMode = PSPDFPageRenderingModeFullPageBlocking;
[pdfController setUpdateSettingsForRotationBlock:^(PSPDFViewController *aPDFController, UIInterfaceOrientation toInterfaceOrientation) {
    // conditionally set depending on rotation
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        aPDFController.pageMode = PSPDFPageModeDouble;
    }  else {
        aPDFController.pageMode = PSPDFPageModeSingle;
    }

}];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pdfController];
[self presentViewController:navController animated:YES completion:NULL];
pdfController.title = @"";
[pdfController release];
[navController release];

Now problem is it takes around 30 to 50 seconds to give these error : Error: NSError *PSPDFError(NSInteger, NSString *_strong, NSError *_autoreleasing *)/35 Error 210: documentRef is nil; cannot get pageRef for page 1. hanging my UI completetly and then it opens with pdfController with nothing


Solution

  • this is the main developer of PSPDFKit.

    When you get "documentRef is nil; cannot get pageRef" - this means that the PDF source used to create the PSPDFDocument is invalid. Check the isValid property on the document to test this programmatically.

    I'm not sure on what version you are, but at least 3.x does not block your UI thread, but simply show an empty view controller that's waiting for you to set a different document.