modesArr = new ArrayList<>();
422 | for (int i = 0; i < args.length(); i++) {
423 | String item = args.getString(i);
424 | ToolManager.ToolMode mode = convStringToToolMode(item);
425 | if (mode != null) {
426 | modesArr.add(mode);
427 | }
428 | }
429 | ToolManager.ToolMode[] modes = modesArr.toArray(new ToolManager.ToolMode[modesArr.size()]);
430 | if (mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
431 | ToolManager toolManager = mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getToolManager();
432 | if (toolManager != null) {
433 | toolManager.disableToolMode(modes);
434 | }
435 | } else {
436 | mToolManagerBuilder = mToolManagerBuilder.disableToolModes(modes);
437 | }
438 | }
439 |
440 | private void setToolMode(String toolMode, CallbackContext callbackContext) {
441 | if (mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
442 | boolean success = false;
443 | ToolManager toolManager = mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getToolManager();
444 | if (toolManager != null) {
445 | ToolManager.ToolMode mode = convStringToToolMode(toolMode);
446 | if (mode != null) {
447 | toolManager.setTool(toolManager.createTool(mode, toolManager.getTool()));
448 | success = true;
449 | }
450 | }
451 | if (!success) {
452 | callbackContext.error("setToolMode to " + toolMode + " failed.");
453 | }
454 | } else {
455 | callbackContext.error("Viewer is not ready yet.");
456 | }
457 | }
458 |
459 | private void setPagePresentationMode(String presentationMode, CallbackContext callbackContext) {
460 | if (mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
461 | boolean success = false;
462 | PDFViewCtrl pdfViewCtrl = mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getPDFViewCtrl();
463 | if (pdfViewCtrl != null) {
464 | PDFViewCtrl.PagePresentationMode mode = convStringToPagePresentationMode(presentationMode);
465 | if (mode != null) {
466 | pdfViewCtrl.setPagePresentationMode(mode);
467 | success = true;
468 | }
469 | }
470 | if (!success) {
471 | callbackContext.error("setPagePresentationMode to " + presentationMode + " failed.");
472 | }
473 | } else {
474 | callbackContext.error("Viewer is not ready yet.");
475 | }
476 | }
477 |
478 | private void loadDocument(String document, CallbackContext callbackContext) {
479 | if (mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
480 | // fragment already inflated
481 | cordova.getActivity().runOnUiThread(() -> {
482 | Bundle args = PdfViewCtrlTabFragment.createBasicPdfViewCtrlTabBundle(cordova.getActivity(), Uri.parse(document), "", getConfig());
483 | mDocumentView.mPdfViewCtrlTabHostFragment.onOpenAddNewTab(args);
484 | callbackContext.success();
485 | });
486 | } else {
487 | callbackContext.error("Viewer is not ready yet, use 'initialDoc' option instead.");
488 | }
489 | }
490 |
491 | private void showDocumentViewer(CallbackContext callbackContext) {
492 | cordova.getActivity().runOnUiThread(() -> {
493 | if (mDocumentView != null) {
494 | try {
495 | attachDocumentViewerImpl();
496 | callbackContext.success();
497 | } catch (Exception ex) {
498 | callbackContext.error(ex.getMessage());
499 | }
500 | }
501 | });
502 | }
503 |
504 | private void save(CallbackContext callbackContext) {
505 | if (mDocumentView != null && mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
506 | mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().save(false, true, true);
507 | callbackContext.success(mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getFilePath());
508 | } else {
509 | callbackContext.error("Saving failed.");
510 | }
511 | }
512 |
513 | private ViewerConfig getConfig() {
514 | return mBuilder
515 | .toolManagerBuilder(mToolManagerBuilder)
516 | .build();
517 | }
518 | }
519 |
--------------------------------------------------------------------------------
/src/android/org/apache/cordova/CordovaAppCompatActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 | package org.apache.cordova;
20 |
21 | import android.annotation.SuppressLint;
22 | import android.app.AlertDialog;
23 | import android.content.DialogInterface;
24 | import android.content.Intent;
25 | import android.content.res.Configuration;
26 | import android.graphics.Color;
27 | import android.media.AudioManager;
28 | import android.os.Bundle;
29 | import android.view.Menu;
30 | import android.view.MenuItem;
31 | import android.view.View;
32 | import android.view.ViewGroup;
33 | import android.view.Window;
34 | import android.view.WindowManager;
35 | import android.webkit.WebViewClient;
36 | import android.widget.FrameLayout;
37 |
38 | import org.json.JSONException;
39 | import org.json.JSONObject;
40 |
41 | import java.util.ArrayList;
42 | import java.util.Locale;
43 |
44 | import androidx.appcompat.app.AppCompatActivity;
45 |
46 | /**
47 | * This class is the main Android activity that represents the Cordova
48 | * application. It should be extended by the user to load the specific
49 | * html file that contains the application.
50 | *
51 | * As an example:
52 | *
53 | *
54 | * package org.apache.cordova.examples;
55 | *
56 | * import android.os.Bundle;
57 | * import org.apache.cordova.*;
58 | *
59 | * public class Example extends CordovaActivity {
60 | * @Override
61 | * public void onCreate(Bundle savedInstanceState) {
62 | * super.onCreate(savedInstanceState);
63 | * super.init();
64 | * // Load your application
65 | * loadUrl(launchUrl);
66 | * }
67 | * }
68 | *
69 | *
70 | * Cordova xml configuration: Cordova uses a configuration file at
71 | * res/xml/config.xml to specify its settings. See "The config.xml File"
72 | * guide in cordova-docs at http://cordova.apache.org/docs for the documentation
73 | * for the configuration. The use of the set*Property() methods is
74 | * deprecated in favor of the config.xml file.
75 | *
76 | */
77 | public class CordovaAppCompatActivity extends AppCompatActivity {
78 | public static String TAG = "CordovaActivity";
79 |
80 | // The webview for our app
81 | protected CordovaWebView appView;
82 |
83 | private static int ACTIVITY_STARTING = 0;
84 | private static int ACTIVITY_RUNNING = 1;
85 | private static int ACTIVITY_EXITING = 2;
86 |
87 | // Keep app running when pause is received. (default = true)
88 | // If true, then the JavaScript and native code continue to run in the background
89 | // when another application (activity) is started.
90 | protected boolean keepRunning = true;
91 |
92 | // Flag to keep immersive mode if set to fullscreen
93 | protected boolean immersiveMode;
94 |
95 | // Read from config.xml:
96 | protected CordovaPreferences preferences;
97 | protected String launchUrl;
98 | protected ArrayList pluginEntries;
99 | protected CordovaInterfaceImpl cordovaInterface;
100 |
101 | /**
102 | * Called when the activity is first created.
103 | */
104 | @Override
105 | public void onCreate(Bundle savedInstanceState) {
106 | // need to activate preferences before super.onCreate to avoid "requestFeature() must be called before adding content" exception
107 | loadConfig();
108 |
109 | String logLevel = preferences.getString("loglevel", "ERROR");
110 | LOG.setLogLevel(logLevel);
111 |
112 | LOG.i(TAG, "Apache Cordova native platform version " + CordovaWebView.CORDOVA_VERSION + " is starting");
113 | LOG.d(TAG, "CordovaActivity.onCreate()");
114 |
115 | if (!preferences.getBoolean("ShowTitle", false)) {
116 | getWindow().requestFeature(Window.FEATURE_NO_TITLE);
117 | }
118 |
119 | if (preferences.getBoolean("SetFullscreen", false)) {
120 | LOG.d(TAG, "The SetFullscreen configuration is deprecated in favor of Fullscreen, and will be removed in a future version.");
121 | preferences.set("Fullscreen", true);
122 | }
123 | if (preferences.getBoolean("Fullscreen", false)) {
124 | // NOTE: use the FullscreenNotImmersive configuration key to set the activity in a REAL full screen
125 | // (as was the case in previous cordova versions)
126 | if (!preferences.getBoolean("FullscreenNotImmersive", false)) {
127 | immersiveMode = true;
128 | } else {
129 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
130 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
131 | }
132 | } else {
133 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
134 | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
135 | }
136 |
137 | super.onCreate(savedInstanceState);
138 |
139 | cordovaInterface = makeCordovaInterface();
140 | if (savedInstanceState != null) {
141 | cordovaInterface.restoreInstanceState(savedInstanceState);
142 | }
143 | }
144 |
145 | protected void init() {
146 | appView = makeWebView();
147 | createViews();
148 | if (!appView.isInitialized()) {
149 | appView.init(cordovaInterface, pluginEntries, preferences);
150 | }
151 | cordovaInterface.onCordovaInit(appView.getPluginManager());
152 |
153 | // Wire the hardware volume controls to control media if desired.
154 | String volumePref = preferences.getString("DefaultVolumeStream", "");
155 | if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) {
156 | setVolumeControlStream(AudioManager.STREAM_MUSIC);
157 | }
158 | }
159 |
160 | @SuppressWarnings("deprecation")
161 | protected void loadConfig() {
162 | ConfigXmlParser parser = new ConfigXmlParser();
163 | parser.parse(this);
164 | preferences = parser.getPreferences();
165 | preferences.setPreferencesBundle(getIntent().getExtras());
166 | launchUrl = parser.getLaunchUrl();
167 | pluginEntries = parser.getPluginEntries();
168 | Config.parser = parser;
169 | }
170 |
171 | //Suppressing warnings in AndroidStudio
172 | @SuppressWarnings({"deprecation", "ResourceType"})
173 | protected void createViews() {
174 | //Why are we setting a constant as the ID? This should be investigated
175 | appView.getView().setId(100);
176 | appView.getView().setLayoutParams(new FrameLayout.LayoutParams(
177 | ViewGroup.LayoutParams.MATCH_PARENT,
178 | ViewGroup.LayoutParams.MATCH_PARENT));
179 |
180 | setContentView(appView.getView());
181 |
182 | if (preferences.contains("BackgroundColor")) {
183 | try {
184 | int backgroundColor = preferences.getInteger("BackgroundColor", Color.BLACK);
185 | // Background of activity:
186 | appView.getView().setBackgroundColor(backgroundColor);
187 | }
188 | catch (NumberFormatException e){
189 | e.printStackTrace();
190 | }
191 | }
192 |
193 | appView.getView().requestFocusFromTouch();
194 | }
195 |
196 | /**
197 | * Construct the default web view object.
198 | *
199 | * Override this to customize the webview that is used.
200 | */
201 | protected CordovaWebView makeWebView() {
202 | return new CordovaWebViewImpl(makeWebViewEngine());
203 | }
204 |
205 | protected CordovaWebViewEngine makeWebViewEngine() {
206 | return CordovaWebViewImpl.createEngine(this, preferences);
207 | }
208 |
209 | protected CordovaInterfaceImpl makeCordovaInterface() {
210 | return new CordovaInterfaceImpl(this) {
211 | @Override
212 | public Object onMessage(String id, Object data) {
213 | // Plumb this to CordovaActivity.onMessage for backwards compatibility
214 | return org.apache.cordova.CordovaAppCompatActivity.this.onMessage(id, data);
215 | }
216 | };
217 | }
218 |
219 | /**
220 | * Load the url into the webview.
221 | */
222 | public void loadUrl(String url) {
223 | if (appView == null) {
224 | init();
225 | }
226 |
227 | // If keepRunning
228 | this.keepRunning = preferences.getBoolean("KeepRunning", true);
229 |
230 | appView.loadUrlIntoView(url, true);
231 | }
232 |
233 | /**
234 | * Called when the system is about to start resuming a previous activity.
235 | */
236 | @Override
237 | protected void onPause() {
238 | super.onPause();
239 | LOG.d(TAG, "Paused the activity.");
240 |
241 | if (this.appView != null) {
242 | // CB-9382 If there is an activity that started for result and main activity is waiting for callback
243 | // result, we shoudn't stop WebView Javascript timers, as activity for result might be using them
244 | boolean keepRunning = this.keepRunning || this.cordovaInterface.activityResultCallback != null;
245 | this.appView.handlePause(keepRunning);
246 | }
247 | }
248 |
249 | /**
250 | * Called when the activity receives a new intent
251 | */
252 | @Override
253 | protected void onNewIntent(Intent intent) {
254 | super.onNewIntent(intent);
255 | //Forward to plugins
256 | if (this.appView != null)
257 | this.appView.onNewIntent(intent);
258 | }
259 |
260 | /**
261 | * Called when the activity will start interacting with the user.
262 | */
263 | @Override
264 | protected void onResume() {
265 | super.onResume();
266 | LOG.d(TAG, "Resumed the activity.");
267 |
268 | if (this.appView == null) {
269 | return;
270 | }
271 | if (! this.getWindow().getDecorView().hasFocus()) {
272 | // Force window to have focus, so application always
273 | // receive user input. Workaround for some devices (Samsung Galaxy Note 3 at least)
274 | this.getWindow().getDecorView().requestFocus();
275 | }
276 |
277 | this.appView.handleResume(this.keepRunning);
278 | }
279 |
280 | /**
281 | * Called when the activity is no longer visible to the user.
282 | */
283 | @Override
284 | protected void onStop() {
285 | super.onStop();
286 | LOG.d(TAG, "Stopped the activity.");
287 |
288 | if (this.appView == null) {
289 | return;
290 | }
291 | this.appView.handleStop();
292 | }
293 |
294 | /**
295 | * Called when the activity is becoming visible to the user.
296 | */
297 | @Override
298 | protected void onStart() {
299 | super.onStart();
300 | LOG.d(TAG, "Started the activity.");
301 |
302 | if (this.appView == null) {
303 | return;
304 | }
305 | this.appView.handleStart();
306 | }
307 |
308 | /**
309 | * The final call you receive before your activity is destroyed.
310 | */
311 | @Override
312 | public void onDestroy() {
313 | LOG.d(TAG, "CordovaActivity.onDestroy()");
314 | super.onDestroy();
315 |
316 | if (this.appView != null) {
317 | appView.handleDestroy();
318 | }
319 | }
320 |
321 | /**
322 | * Called when view focus is changed
323 | */
324 | @SuppressLint("InlinedApi")
325 | @Override
326 | public void onWindowFocusChanged(boolean hasFocus) {
327 | super.onWindowFocusChanged(hasFocus);
328 | if (hasFocus && immersiveMode) {
329 | final int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
330 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
331 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
332 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
333 | | View.SYSTEM_UI_FLAG_FULLSCREEN
334 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
335 |
336 | getWindow().getDecorView().setSystemUiVisibility(uiOptions);
337 | }
338 | }
339 |
340 | @SuppressLint("NewApi")
341 | @Override
342 | public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
343 | // Capture requestCode here so that it is captured in the setActivityResultCallback() case.
344 | cordovaInterface.setActivityResultRequestCode(requestCode);
345 | super.startActivityForResult(intent, requestCode, options);
346 | }
347 |
348 | /**
349 | * Called when an activity you launched exits, giving you the requestCode you started it with,
350 | * the resultCode it returned, and any additional data from it.
351 | *
352 | * @param requestCode The request code originally supplied to startActivityForResult(),
353 | * allowing you to identify who this result came from.
354 | * @param resultCode The integer result code returned by the child activity through its setResult().
355 | * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
356 | */
357 | @Override
358 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
359 | LOG.d(TAG, "Incoming Result. Request code = " + requestCode);
360 | super.onActivityResult(requestCode, resultCode, intent);
361 | cordovaInterface.onActivityResult(requestCode, resultCode, intent);
362 | }
363 |
364 | /**
365 | * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
366 | * The errorCode parameter corresponds to one of the ERROR_* constants.
367 | *
368 | * @param errorCode The error code corresponding to an ERROR_* value.
369 | * @param description A String describing the error.
370 | * @param failingUrl The url that failed to load.
371 | */
372 | public void onReceivedError(final int errorCode, final String description, final String failingUrl) {
373 | final org.apache.cordova.CordovaAppCompatActivity me = this;
374 |
375 | // If errorUrl specified, then load it
376 | final String errorUrl = preferences.getString("errorUrl", null);
377 | if ((errorUrl != null) && (!failingUrl.equals(errorUrl)) && (appView != null)) {
378 | // Load URL on UI thread
379 | me.runOnUiThread(new Runnable() {
380 | public void run() {
381 | me.appView.showWebPage(errorUrl, false, true, null);
382 | }
383 | });
384 | }
385 | // If not, then display error dialog
386 | else {
387 | final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP);
388 | me.runOnUiThread(new Runnable() {
389 | public void run() {
390 | if (exit) {
391 | me.appView.getView().setVisibility(View.GONE);
392 | me.displayError("Application Error", description + " (" + failingUrl + ")", "OK", exit);
393 | }
394 | }
395 | });
396 | }
397 | }
398 |
399 | /**
400 | * Display an error dialog and optionally exit application.
401 | */
402 | public void displayError(final String title, final String message, final String button, final boolean exit) {
403 | final org.apache.cordova.CordovaAppCompatActivity me = this;
404 | me.runOnUiThread(new Runnable() {
405 | public void run() {
406 | try {
407 | AlertDialog.Builder dlg = new AlertDialog.Builder(me);
408 | dlg.setMessage(message);
409 | dlg.setTitle(title);
410 | dlg.setCancelable(false);
411 | dlg.setPositiveButton(button,
412 | new AlertDialog.OnClickListener() {
413 | public void onClick(DialogInterface dialog, int which) {
414 | dialog.dismiss();
415 | if (exit) {
416 | finish();
417 | }
418 | }
419 | });
420 | dlg.create();
421 | dlg.show();
422 | } catch (Exception e) {
423 | finish();
424 | }
425 | }
426 | });
427 | }
428 |
429 | /*
430 | * Hook in Cordova for menu plugins
431 | */
432 | @Override
433 | public boolean onCreateOptionsMenu(Menu menu) {
434 | if (appView != null) {
435 | appView.getPluginManager().postMessage("onCreateOptionsMenu", menu);
436 | }
437 | return super.onCreateOptionsMenu(menu);
438 | }
439 |
440 | @Override
441 | public boolean onPrepareOptionsMenu(Menu menu) {
442 | if (appView != null) {
443 | appView.getPluginManager().postMessage("onPrepareOptionsMenu", menu);
444 | }
445 | return true;
446 | }
447 |
448 | @Override
449 | public boolean onOptionsItemSelected(MenuItem item) {
450 | if (appView != null) {
451 | appView.getPluginManager().postMessage("onOptionsItemSelected", item);
452 | }
453 | return true;
454 | }
455 |
456 | /**
457 | * Called when a message is sent to plugin.
458 | *
459 | * @param id The message id
460 | * @param data The message data
461 | * @return Object or null
462 | */
463 | public Object onMessage(String id, Object data) {
464 | if ("onReceivedError".equals(id)) {
465 | JSONObject d = (JSONObject) data;
466 | try {
467 | this.onReceivedError(d.getInt("errorCode"), d.getString("description"), d.getString("url"));
468 | } catch (JSONException e) {
469 | e.printStackTrace();
470 | }
471 | } else if ("exit".equals(id)) {
472 | finish();
473 | }
474 | return null;
475 | }
476 |
477 | protected void onSaveInstanceState(Bundle outState) {
478 | cordovaInterface.onSaveInstanceState(outState);
479 | super.onSaveInstanceState(outState);
480 | }
481 |
482 | /**
483 | * Called by the system when the device configuration changes while your activity is running.
484 | *
485 | * @param newConfig The new device configuration
486 | */
487 | @Override
488 | public void onConfigurationChanged(Configuration newConfig) {
489 | super.onConfigurationChanged(newConfig);
490 | if (this.appView == null) {
491 | return;
492 | }
493 | PluginManager pm = this.appView.getPluginManager();
494 | if (pm != null) {
495 | pm.onConfigurationChanged(newConfig);
496 | }
497 | }
498 |
499 | /**
500 | * Called by the system when the user grants permissions
501 | *
502 | * @param requestCode
503 | * @param permissions
504 | * @param grantResults
505 | */
506 | @Override
507 | public void onRequestPermissionsResult(int requestCode, String permissions[],
508 | int[] grantResults) {
509 | try
510 | {
511 | cordovaInterface.onRequestPermissionResult(requestCode, permissions, grantResults);
512 | }
513 | catch (JSONException e)
514 | {
515 | LOG.d(TAG, "JSONException: Parameters fed into the method are not valid");
516 | e.printStackTrace();
517 | }
518 |
519 | }
520 |
521 | }
522 |
--------------------------------------------------------------------------------
/src/android/pdftron.gradle:
--------------------------------------------------------------------------------
1 | repositories {
2 | google()
3 | maven {
4 | url "https://pdftron-maven.s3.amazonaws.com/release"
5 | }
6 | }
7 |
8 | android {
9 | defaultConfig {
10 | multiDexEnabled true
11 | vectorDrawables.useSupportLibrary = true
12 | manifestPlaceholders = [pdftronLicenseKey:PDFTRON_LICENSE_KEY]
13 | }
14 | }
15 | dependencies {
16 | implementation "com.pdftron:pdftron:8.0.0"
17 | implementation "com.pdftron:tools:8.0.0"
18 |
19 | implementation 'com.android.support:multidex:1.0.3'
20 | }
--------------------------------------------------------------------------------
/src/ios/PDFTron.h:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | #import
21 | #import
22 |
23 | @interface PDFTron : CDVPlugin
24 | {}
25 |
26 |
27 |
28 | - (void)coolMethod:(CDVInvokedUrlCommand*)command;
29 |
30 | - (void)showDocumentViewer:(CDVInvokedUrlCommand*)command;
31 |
32 | -(void)disableElements:(CDVInvokedUrlCommand*)command;
33 |
34 | -(void)enableTools:(CDVInvokedUrlCommand*)command;
35 |
36 | -(void)disableTools:(CDVInvokedUrlCommand*)command;
37 |
38 | -(void)setToolMode:(CDVInvokedUrlCommand*)command;
39 |
40 | -(void)setPagePresentationMode:(CDVInvokedUrlCommand*)command;
41 |
42 | -(void)loadDocument:(CDVInvokedUrlCommand*)command;
43 |
44 | -(void)NativeViewer:(CDVInvokedUrlCommand*)command;
45 |
46 | -(void)messageChannel:(CDVInvokedUrlCommand*)command;
47 |
48 | -(void)save:(CDVInvokedUrlCommand*)command;
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/www/PDFTron.js:
--------------------------------------------------------------------------------
1 |
2 | var exec = require('cordova/exec');
3 |
4 |
5 | function PDFTron() {
6 | var me = this;
7 | }
8 |
9 | PDFTron.prototype.showDocumentViewer = function (success, error) {
10 | exec(success, error, 'PDFTron', 'showDocumentViewer', []);
11 | };
12 |
13 | function NativeViewer(dictionary, element, success, error) {
14 | if (element) {
15 | exec(success, error, 'PDFTron', 'NativeViewer', [dictionary, element.id]);
16 | } else {
17 | exec(success, error, 'PDFTron', 'NativeViewer', [dictionary]);
18 | }
19 |
20 | exec(onMessageFromNative, null, 'PDFTron', 'messageChannel', []);
21 | };
22 |
23 | function onMessageFromNative(msg) {
24 | var cordova = require('cordova');
25 | var action = msg.action;
26 |
27 | switch (action) {
28 | // PDFTron events
29 | case 'topLeftButtonPressed':
30 | case 'documentLoaded':
31 | cordova.fireDocumentEvent(action);
32 | break;
33 | default:
34 | throw new Error('Unknown event action ' + action);
35 | }
36 | };
37 |
38 | PDFTron.prototype.NativeViewer = NativeViewer;
39 |
40 | NativeViewer.prototype.disableElements = function (arguments, success, error) {
41 | exec(success, error, 'PDFTron', 'disableElements', arguments);
42 | };
43 |
44 | NativeViewer.prototype.enableTools = function (arguments, success, error) {
45 | exec(success, error, 'PDFTron', 'enableTools', arguments);
46 | };
47 |
48 | NativeViewer.prototype.disableTools = function (arguments, success, error) {
49 | exec(success, error, 'PDFTron', 'disableTools', arguments);
50 | };
51 |
52 | NativeViewer.prototype.setToolMode = function (arguments, success, error) {
53 | exec(success, error, 'PDFTron', 'setToolMode', [arguments]);
54 | };
55 |
56 | NativeViewer.prototype.setPagePresentationMode = function (arguments, success, error) {
57 | exec(success, error, 'PDFTron', 'setPagePresentationMode', [arguments]);
58 | };
59 |
60 | NativeViewer.prototype.loadDocument = function (arguments, success, error) {
61 | exec(success, error, 'PDFTron', 'loadDocument', [arguments]);
62 | };
63 |
64 | NativeViewer.prototype.showDocumentViewer = function (success, error) {
65 | exec(success, error, 'PDFTron', 'showDocumentViewer', []);
66 | };
67 |
68 | NativeViewer.prototype.save = function (success, error) {
69 | exec(success, error, 'PDFTron', 'save', []);
70 | };
71 |
72 | module.exports = new PDFTron();
73 |
--------------------------------------------------------------------------------