All Projects → sitewaerts → Cordova Plugin Document Viewer

sitewaerts / Cordova Plugin Document Viewer

Licence: mit
A Document Viewer cordova/phonegap plugin for iOS, Android and Windows

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Cordova Plugin Document Viewer

Sumatrapdf
SumatraPDF reader
Stars: ✭ 7,462 (+4341.67%)
Mutual labels:  pdf, pdf-viewer
Jfbview
PDF and image viewer for the Linux framebuffer.
Stars: ✭ 78 (-53.57%)
Mutual labels:  pdf, pdf-viewer
Buka
Buka is a modern software that helps you manage your ebook at ease.
Stars: ✭ 896 (+433.33%)
Mutual labels:  pdf, pdf-viewer
React Pdf
Display PDFs in your React app as easily as if they were images.
Stars: ✭ 5,320 (+3066.67%)
Mutual labels:  pdf, pdf-viewer
Pdf Generator
Cordova plugin to generate pdf in the client-side
Stars: ✭ 98 (-41.67%)
Mutual labels:  pdf, cordova
Pdf2htmlex
Convert PDF to HTML without losing text or format.
Stars: ✭ 472 (+180.95%)
Mutual labels:  pdf, pdf-viewer
Framework7 Plugin 3d Panels
Framework7 plugin to add 3d effect for side panels
Stars: ✭ 56 (-66.67%)
Mutual labels:  plugin, cordova
Document Viewer
Document Viewer is a highly customizable document viewer for Android.
Stars: ✭ 415 (+147.02%)
Mutual labels:  pdf, pdf-viewer
Unityionicintegration
A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
Stars: ✭ 94 (-44.05%)
Mutual labels:  plugin, cordova
Sentinl
Kibana Alert & Report App for Elasticsearch
Stars: ✭ 1,233 (+633.93%)
Mutual labels:  plugin, pdf
React Pdf Highlighter
Set of React components for PDF annotation
Stars: ✭ 448 (+166.67%)
Mutual labels:  pdf, pdf-viewer
Vue Pdf
vue.js pdf viewer
Stars: ✭ 1,700 (+911.9%)
Mutual labels:  pdf, pdf-viewer
Pdfvuer
A PDF viewer for Vue using Mozilla's PDF.js
Stars: ✭ 443 (+163.69%)
Mutual labels:  pdf, pdf-viewer
React Pdf Js
A React component to wrap PDF.js
Stars: ✭ 489 (+191.07%)
Mutual labels:  pdf, pdf-viewer
Pdfh5
web/h5/移动端PDF预览插件
Stars: ✭ 423 (+151.79%)
Mutual labels:  pdf, pdf-viewer
Ng2 Pdf Viewer
📄 PDF Viewer Component for Angular 5+
Stars: ✭ 997 (+493.45%)
Mutual labels:  pdf, pdf-viewer
Pdf Flipbook
Browse PDF document like a book turning its pages
Stars: ✭ 279 (+66.07%)
Mutual labels:  pdf, pdf-viewer
Xournalpp
Xournal++ is a handwriting notetaking software with PDF annotation support. Written in C++ with GTK3, supporting Linux (e.g. Ubuntu, Debian, Arch, SUSE), macOS and Windows 10. Supports pen input from devices such as Wacom Tablets.
Stars: ✭ 5,353 (+3086.31%)
Mutual labels:  pdf, pdf-viewer
Flutter plugin pdf viewer
A flutter plugin for handling PDF files. Works on both Android & iOS
Stars: ✭ 81 (-51.79%)
Mutual labels:  pdf, pdf-viewer
Qpdf
PDF viewer widget for Qt
Stars: ✭ 111 (-33.93%)
Mutual labels:  pdf, pdf-viewer

Cordova Document Viewer Plugin

!!! This plugin is no longer maintained. For a cross platform pdf viewer take a look at pdf.js !!!

A common requirement when developing a cordova based app is to embed a performant and secure inline viewer for pdf files which doesn't allow the user to extract a copy of the pdf file out of the apps sandbox.

Simple delegation to commonly available viewer apps like Acrobat Reader or MuPDF is no proper solution, as the app looses control over the pdf file in this case. The external viewer app may or may not provide features to send the document via email or save it to the devices disk, which is not acceptable.

This plugin offers a slim API to view PDF files which are either stored in the apps assets folder (/www/*) or in any other file system directory available via the cordova file plugin (e.g. cordova.file.applicationDirectory, cordova.file.dataDirectory).

Online files reachable via http(s) are not supported. Download them to a temp folder before starting the viewer. You may use the onClose callback to cleanup the temp dir when the viewer is closed.

Viewer features like "Save as" or "Send via EMail" are configurable at runtime.

Labels for buttons (i18n) are configurable at runtime.

Plugin's Purpose

The purpose of the plugin is to create a platform independent javascript interface for Cordova based mobile applications to view different document types by using native viewer components.

Overview

  1. Supported Platforms
  2. Installation
  3. Using the plugin
  4. Known issues

Supported Platforms

  • Cordova/Phonegap >=4.4.0
    • iOS 7+
    • Android 4.1+
    • Windows 8.1
    • Windows 10

Installation

The plugin can either be installed from git repository, from local file system through the Command-line Interface, or cloud based through PhoneGap Build.

The plugin is published at the npm plugin registry.

An ionic native wrapper for the plugin is available.

Local development environment

From master:

# ~~ from master branch ~~
cordova plugin add https://github.com/sitewaerts/cordova-plugin-document-viewer.git

from a local folder:

# ~~ local folder ~~
cordova plugin add cordova-plugin-document-viewer --searchpath path/to/plugin

or to use the last stable version:

# ~~ stable version ~~
cordova plugin add cordova-plugin-document-viewer

or to use a specific version:

# ~~ stable version ~~
cordova plugin add [email protected][VERSION]

You may replace cordova with phonegap regarding to your needs.

PhoneGap Build

Add the following xml to your config.xml to always use the latest version of this plugin:

<gap:plugin name="cordova-plugin-document-viewer" />

or a specific version:

<gap:plugin name="cordova-plugin-document-viewer" version="[VERSION]"/>

For available versions and additional information visit the npm plugin registry.

Using the plugin

See https://github.com/sitewaerts/cordova-plugin-document-viewer-sample-app for a working example.

The plugin creates the object cordova.plugins.SitewaertsDocumentViewer.

Plugin initialization

The plugin and its methods are not available before the deviceready event has been fired.

document.addEventListener('deviceready', function () {
    // cordova.plugins.SitewaertsDocumentViewer is now available
}, false);

Common Arguments

url

String pointing to a device local file (e.g. 'file:///...')

mimeType

String representing the mime type of the file. Currently only 'application/pdf' is supported.

options

Some optional features like search or bookmarks are not (yet) implemented on every platform!

var options = {
	title: STRING,
	documentView : {
		closeLabel : STRING
	},
	navigationView : {
		closeLabel : STRING
	},
	email : {
		enabled : BOOLEAN
	},
	print : {
		enabled : BOOLEAN
	},
	openWith : {
		enabled : BOOLEAN
	},
	bookmarks : {
		enabled : BOOLEAN
	},
	search : {
		enabled : BOOLEAN
	},
	autoClose: {
		onPause : BOOLEAN
	}
}

Check if a Viewer File could be shown

cordova.plugins.SitewaertsDocumentViewer.canViewDocument(
    url, contentType, options, onPossible, onMissingApp, onImpossible, onError);

onPossible

function onPossible(){
  window.console.log('document can be shown');
  //e.g. track document usage
}

onMissingApp

function onMissingApp(appId, installer)
{
    if(confirm("Do you want to install the free PDF Viewer App "
            + appId + " for Android?"))
    {
        installer();
    }
}

onImpossible

function onImpossible(){
  window.console.log('document cannot be shown');
  //e.g. track document usage
}

onError

function onError(error){
  window.console.log(error);
  alert("Sorry! Cannot show document.");
}

Open a Viewer File

cordova.plugins.SitewaertsDocumentViewer.viewDocument(
    url, mimeType, options, onShow, onClose, onMissingApp, onError, linkHandlers);

onShow

function onShow(){
  window.console.log('document shown');
  //e.g. track document usage
}

onClose

function onClose(){
  window.console.log('document closed');
  //e.g. remove temp files
}

onMissingApp

function onMissingApp(appId, installer)
{
    if(confirm("Do you want to install the free PDF Viewer App "
            + appId + " for Android?"))
    {
        installer();
    }
} 

onError

function onError(error){
  window.console.log(error);
  alert("Sorry! Cannot view document.");
}

linkHandlers

Currently only supported on iOS!

Array of link handlers. Optional.

Links in the pdf (when clicked by the user) are delegated to the first linkHandler with a matching pattern. If no matching pattern is found, the link is handled with the default link handler of the native viewer component (if any).

var linkHandlers = [
            {
                pattern: STRING, // string representation of a plain regexp (no flags)
                close: BOOLEAN, // shall the document be closed, after the link handler was executed?
                handler: function (link) {} // link handler to be executed when the user clicks on a link matching the pattern
            },
            {
                pattern: '^\/',
                close: false,
                handler: function (link) {
                    window.console.log('link clicked: ' + link);
                }
            }
    ];

Close the viewer

cordova.plugins.SitewaertsDocumentViewer.closeDocument(onClose, onError);

onShow

function onClose(url){
    if(url)
        window.console.log('closed viewer document ' + url);
    else
        window.console.log('viewer not open');
}

onError

function onError(error){
  window.console.log(error);
  alert("Sorry! Cannot close viewer.");
}

iOS

The plugin uses the awesome VFRReader (https://github.com/vfr/Reader) to embed pdf viewer functionality in the app.

To open a pdf at a given page number add { page: pageIndex } to the options when calling viewDocument.

Screenshots

screenshot    screenshot

screenshot    screenshot

Android

Due to license restrictions in muPDF, the plugin dispatches to a separate (free) viewer app based on muPDF. If the viewer app is not yet installed, the user may be redirected to the google play app store.

https://play.google.com/store/apps/details?id=de.sitewaerts.cleverdox.viewer

https://github.com/sitewaerts/android-document-viewer

Screenshots

screenshot    screenshot

Windows

The plugin uses

Screenshots

TODO

Known issues

  • Add transparent support for online files.
  • The external Viewer App (Android) cannot access files stored in app private directories. Due to this fact, the plugin copies a file to a shared temp folder before starting the viewer. When the viewer is closed, the temp file is immediately deleted. While the viewer is running, a sophisticated user may 'steal' the file from the shared temp directory. We are still searching for a better solution, any good idea is welcome.
  • Add support for pdf forms.
  • Add fulltext search features.
  • Add user bookmark support.
  • Add support for additional mime types like dwg, docx, etc.
  • Optimize user experience for small screens. Currently the viewer components are tested and optimized on tablets only.
  • Let developers provide graphics for buttons at runtime.

Credits

based on https://github.com/vfr/Reader

based on https://github.com/mindstorm/CDVPDFViewer

based on pdf.js

based on winjs

inspired by https://github.com/pebois/phonegap-plugin-PDFViewer

inspired by https://msdn.microsoft.com/en-us/library/windows/apps/dn263105.aspx

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].