This plugin adds the ability to easily preview any PDF file in your Cordova application
cordova plugin add cordova-plugin-foxitpdf
It is also possible to install via repo url directly ( unstable )
cordova plugin add https://github.com/foxitsoftware/cordova-plugin-foxitpdf.git
Large files in the plugin may cause your update to fail. If that is the case, please try again following the steps below:
cordova plugin add ~/xxx/cordova-plugin-foxitpdf (This address is replaced by your own)
The iOS version of the cordova plugin only needs a few simple steps to deploy
/xxx/platforms/ios/
)Please use foxitpdfsdk_(version_no)_ios.zip from https://developers.foxitsoftware.com/pdf-sdk/ios/
Target -> General -> Embedded Binaries Add dynamic framework "FoxitRDK.framework" 、"uiextensionsDynamic.framework" and "FoxitPDFScanUI.framework" to Xcode’s Embedded Binaries
Target -> General -> Linked Frameworks and Libraries -> + -> WebKit.framework
Note
Do not forget to add pdf files You can add the PDF to Copy Bundle Resources directly. Just left-click the project, find 'Copy Bundle Resources' in the 'Build Phases' tab, click on the + button, and choose the file to add. You can refer to any PDF file, just add it to the Xcode’s Copy Bundle Resources. Or,you can use the pdf file under Document directory in sandbox
Now that the preparatory work has been completed,you can use this plugin everywhere in your project.
Migrating to AndroidX, Add the following configuration to xxx/platforms/android/gradle.propertie:
android.useAndroidX=true
android.enableJetifier=true
Download foxitpdfsdk_(version_no)_android.zip
from https://developers.foxitsoftware.com/pdf-sdk/android/ (Please use Foxit PDF SDK for Android 7.2.1)
Unzip foxitpdfsdk_(version_no)_android.zip
and copy libs folder into the component’s android folder.
/xxx/platforms/android/
- Initialize
var sn = 'foxit_sn'; var key = 'foxit_key'; window.FoxitPdf.initialize(sn,key);
> 2. Open Pdf File
```javascript
var path = 'Your file path';
var password = 'password'; // If the PDF document is not encrypted by password, just pass an empty string.
window.FoxitPdf.openDocument(path, password);
For Foxit PDF SDK for iOS. The UI is handled within the "FoxitRDK.framework" and "uiextensionsDynamic.framework." The files that comes with the evaluation package, however, they also comes with the source, which you can compile and replace accordingly. The UI source can be located at "libs\uiextensions_src" You can find the uiextensions.xcodeproj in the same directory. Just open this project with xcode, modified it to your needs, build, and replace them accordingly in step 2 of the instruction at https://github.com/foxitsoftware/cordova-plugin-foxitpdf#integration-for-ios.
For Android, the UI is located at the binary at libs\FoxitRDKUIExtensions.aar. You can find the source for this binary in the package at foxitpdfsdk_XXX_android.zip at libs\uiextensions_src. You can open this project with Android Studio, modified it, and replaced the FoxitRDKUIExtensions.aar file accordingly. Step 2 of https://github.com/foxitsoftware/cordova-plugin-foxitpdf#integration-for-android is where the instructions on the github page indicates that it is being used.
window.FoxitPdf.initialize(sn,key);
options: Initialization options.
__foxit_sn__: the foxit_sn
string
__foxit_key__: the foxit_key
string
foxit_sn
and foxit_key
are required, otherwise the initialization will fail. rdk_key
and rdk_sn
can be found in the libs folder of foxitpdfsdk_(version_no)_ios.zip
.
var sn = 'foxit_sn';
var key = 'foxit_key';
window.FoxitPdf.initialize(sn,key);
window.FoxitPdf.enableAnnotations(enable);
Note: To make it work, this function should be called before opening a document.
var enable = false;
window.FoxitPdf.enableAnnotations(enable);
window.FoxitPdf.openDocument(path, password);
Note: The document can only be opened if the initialization is successful.
var path = 'Your file path';
var password = 'password'; // If the PDF document is not encrypted by password, just pass an empty string.
window.FoxitPdf.openDocument(path, password);
window.FoxitPdf.setSavePath(savePath);
var savePath = 'Your file path';// Document path that prevents overwriting on the preview file _(if set)_
window.FoxitPdf.setSavePath(savePath);
window.FoxitPdf.importFromFDF(fdf_doc_path, data_type, page_range);
fdf_doc_path
: A valid fdf file path, from which form fields and annotations will be imported.data_type
__: Used to decide which kind of data will be imported. this can be one or a combination of as following values:
0x0001
: Form fields are imported from or exported to FDF/XFDF document.0x0002
: Annotations (except Movie, Widget, Screen, PrinterMark and TrapNet, link) are imported from or exported to FDF/XFDF document.0x0004
: links are imported from or exported to XFDF document.Not supported right nowpage_range
__: A integer range array that specifies some pages. Data (in specified types) from FDF/XFDF document will be imported to these specified pages range for importing. In this array, 2 numbers are a pair: the first integer is the starting page index, and the second integer is the page count. Default value: an empty range by default and not set any value.It only support annotations.
var fdf_doc_path = 'Your file path';// FDF file path
var data_type = 0x0002;
var page_range = [[0,1],[2,3]]//[[start1, count1], [start2, count2]....]
window.FoxitPdf.importFromFDF(fdf_doc_path, data_type, page_range);
window.FoxitPdf.exportToFDF(export_path, data_type, fdf_doc_type, page_range);
export_path
__: A valid path to which form fields and annotations will be exported.data_type
__: Used to decide which kind of data will be imported. this can be one or a combination of as following values:
0x0001
: Form fields are imported from or exported to FDF/XFDF document.0x0002
: Annotations (except Movie, Widget, Screen, PrinterMark and TrapNet, link) are imported from or exported to FDF/XFDF document.0x0004
: links are imported from or exported to XFDF document.Not supported right nowfdf_doc_type
: FDF document type. 0 means FDF, and 1 means XFDF
.page_range
__: A integer range array that specifies some pages. Data (in specified types) from FDF/XFDF document will be imported to these specified pages range for importing. In this array, 2 numbers are a pair: the first integer is the starting page index, and the second integer is the page count. Default value: an empty range by default and not set any value.It only support annotations.
var fdf_doc_type = 0;
var export_path = '/Documents/annot_export.fdf';
var page_range = [[0,1],[2,3]]//[[start1, count1], [start2, count2]....]
var data_type = 0x0002;
window.FoxitPdf.exportToFDF(export_path, data_type, fdf_doc_type, page_range);
window.FoxitPdf.addEventListener(eventname,callback);
eventname: The name of the event to listen for (String)
onDocWillSave: This event fires when the document will be saved.
onDocSaved: This event fires when the document is saved.
onDocOpened: This event fires when the document is Opened.
callback: This function is executed when the event fires. The function is passed an object as a parameter.
Add a listener for an event
window.FoxitPdf.addEventListener('onDocSaved',function(data){
console.log('onDocSaved callback ',data);
});
window.FoxitPdf.addEventListener('onDocOpened',function(data){
console.log('onDocOpened callback ',data);
});
Form.getAllFormFields();
Return: An array of dictionaries will be returned, which contains all the form fields in the document, each field is represented as a dictionary, the following are the key/value pairs for the dictionary. Please refer to https://developers.foxitsoftware.com/resources/pdf-sdk/cplusplus_api_reference/index.html for more detail information about parameters such as fieldType, fieldFlag.... (Use keyword "Field" to search)
Form.getForm();
Return: An dictionary will be returned, which contains the form related info. The following are the key/value pairs for the dictionary.
Form.updateForm(formInfo);
Parameters:The parameter for this API is a dictionary, and following are the key/value pairs for the dictionary.
Form.validateFieldName(fieldType,fieldName);
Parameters:
Return: true means the input field name is valid for the specified field type, false means not.
Form.renameField(fieldIndex,newFieldName);
Parameters:
Return: true means success, while false means failure.
Form.removeField(fieldIndex);
Parameters:
Form.reset();
Reset data of all fields (except signature fields) to their default value.
Return true means success, while false means failure.
Form.exportToXML(filePath); Export the form data to an XML file.
Parameters:
Return true means success, while false means failure.
Form.importFromXML(filePath); Import the form data from an XML file.
Parameters:
Return true means success, while false means failure.
Form.getPageControls(pageIndex);
Parameters:
Return: An array of dictionaries will be returned, each dictionary contains the form related info. The following are the key/value pairs for the dictionary.
Form.removeControl(pageIndex, controlIndex);
Parameters:
Form.addControl(pageIndex,fieldName,fieldType,rect);
Parameters:
Return: An dictionary will be returned, which contains the form related info. The following are the key/value pairs for the dictionary.
Form.updateControl(pageIndex,controlIndex, control);
This API is only valid for field type of checkbox and radiobutton.
Parameters:
Form.getFieldByControl(pageIndex,controlIndex);
Parameters:
Return: Please refer to the return info of Form.getAllFormFields
Field.updateField(fieldIndex,field);
Parameters:
Field.reset(fieldIndex);
Parameters:
Field.getFieldControls(fieldIndex);
Parameters:
Return: An array of dictionaries will be returned, each dictionary contains the form related info. The following are the key/value pairs for the dictionary.
ScanPdf.initializeScanner(serial1,serial2);
Initialize the scan module with additional parameters. This function must be called before any App Framework SDK object can be instantiated. Successful initialization of the SDK requires a valid serial number.
ScanPdf.initializeCompression(serial1,serial2);
Initialize the Mobile Compression SDK.
ScanPdf.createScanner();
Show scan file list
Note: The scan list can only be create if the initializeScanner & initializeCompression successful.
ScanPdf.addEventListener(eventname,callback);
eventname: The name of the event to listen for (String)
onDocumentAdded: This event fires when the scan doc added successed.
callback: This function is executed when the event fires. The function is passed an object as a parameter.
Add a listener for an event
ScanPdf.addEventListener('onDocumentAdded',function(data){
console.log('onDocumentAdded callback ',data);
var errorCode = data.error;
if(errorCode == 0){
var filePath = data.info;
window.FoxitPdf.openDocument(filePath, null);
}
});
Please see our forum for more detailed information:
PPTX - How to use cordova-plugin-foxitpdf
iOS
Android
You can obtain the absolute path to the file using the method provided by the [cordova-plugin-file] (https://github.com/apache/cordova-plugin-file) plugin.
Use the following command to add the [cordova-plugin-file] (https://github.com/apache/cordova-plugin-file) plugin to your project
cordova plugin add cordova-plugin-file
If an error similar to the one in the following picture appears, try the method in step 2
A PDF file needs to be placed in the project beforehand. The location is in the project root by default
var filePathSaveTo = cordova.file.documentsDirectory + 'getting_started_ios_2.pdf'
window.FoxitPdf.setSavePath(filePathSaveTo);
var filePath cordova.file.applicationDirectory + 'getting_started_ios.pdf';
window.FoxitPdf.openDocument(filePath,'');
window.FoxitPdf.addEventListener('onDocOpened',function(data){
console.log('onDocOpened callback ',data);
console.log('onDocOpened callback info',data.info);
if (data.error == 0){
var data_type = 0x0002;
window.FoxitPdf.importFromFDF(cordova.file.documentsDirectory + 'Annot_all.fdf',data_type, [[0, 1]]);
}
});
The product is still in its early stage of development. We will continue to focus on refining and improving this project.
If your cordova version is 7.0.0, you might encounter this problem: no such file or directory, open 'xxxx/platforms/android/AndroidManifest.xml' this is a cordova bug, and the solution is provided in the link below: https://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html
However this a major breaking change for people creating standalone Cordova Android projects. This also means that the locations of files have changed and have been brought in line to the structure used by Android Studio. This may affect plugin.xml files and config.xml files that use edit-config, and make it so plugins that use edit-config will not be able to be compatible with both Android 6.x and Android 7.x. To fix this issue, please do the following in your XML files
You can ask us questions or report bugs in here.
You can also send email [email protected] to explain your problem.
If you have a better code implementation, please fork this project and launch your Pull-Request, we will promptly deal with. Thanks!
If you encounter “Invalid license” tips, please go to the following URL for official trial license key:
https://developers.foxitsoftware.com/support