RDIntegration library lets your app interact with PDF Expert on iPad. Using this library you'll be able to open PDF files in PDF Expert from your own application. Also there is an option that allows your app to receive modified file back.
The library does not use standard “Open In” dialogs keeping user expirience clean and simple. Users may launch PDF Expert with required file just by touching single button.
Let's consider there is Your app and PDF Expert. Your app has a PDF file which needs to be viewed and/or edited within PDF Expert. You have a few options:
Simply open PDF file in PDF Expert without returning the modified PDF back
Edit PDF file in PDF Expert and return the modifed version to Your app
Edit PDF file in PDF Expert and return the flattened version to Your app
We call a PDF file “flattened” when additonal annotations are embedded in the body of PDF file. Viewing of this kind of files is supported by iOS system libraries.
First you need to prepare RDIntegration library for using inside your project. RDIntegration library consists of one binary file ‘libRDIntegration.a‘ and one header file ‘RDIntegration.h‘. Please copy these files into your project.
To open a PDF file in PDF Expert use the following code:
- (void)openIn:(NSString *)userInfo { NSString *fullpath = userInfo; RDIntegration *integration = [RDIntegration sharedIntegration]; [integration openFile:[NSURL fileURLWithPath:fullpath] inApp:RDIntegrationAppPDFExpert error:nil]; }
1. Register the URL entry:
Add an entry to URL Types. The identifier must have suffix -rdiback, e.g. com.company.appname-rdiback.
Set the URL Schemes entry in accordance to your application name and with suffix back: e.g. applicationback.
2. Add the following code to edit the file in PDF Expert and receive a not-flattened file back:
- (void)editInRaw:(NSString *)userInfo { NSString *fullpath = userInfo; RDIntegration *integration = [RDIntegration sharedIntegration]; [integration editFile:[NSURL fileURLWithPath:fullpath] inApp:RDIntegrationAppPDFExpert withFlattening:NO error:nil userInfo:userInfo]; }
To receive a flattened file back set withFlattening: to YES.
3. To receive back the edited PDF file:
Adopt RDIntegrationDelegate protocol to handle where and how file will be saved
Add handling open url
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { BOOL handledByRDIntegration = [[RDIntegration sharedIntegration] handleOpenURL:url]; if (handledByRDIntegration) return YES; // regular openURL code return YES; }
A few words should be mentioned about replacing existing files. Decision on replacing files is made on the basis of their modification dates. If you send some pdf file to PDF Expert which already contains the file with the same name, few variants are possible:
If the modification date is equal for PDF file being sent and for identically named file in PDF Expert - the latter will be replaced with the one being sent.
If the modification date differs - new unique name will be generated for the existing file in PDF Expert. E.g. for file ‘file.pdf‘ a newly generated file name will be ‘file(1).pdf‘
For the example of the RDIntegration library usage please refer to RDIntegration sample Xcode project.