Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
cordova-plugin-document-viewer
Advanced tools
PDF Document viewer cordova plugin for iOS, Android and Windows 8.1 + 10
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.
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.
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.
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 cordova-plugin-document-viewer@[VERSION]
You may replace cordova with phonegap regarding to your needs.
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.
See https://github.com/sitewaerts/cordova-plugin-document-viewer-sample-app for a working example.
The plugin creates the object cordova.plugins.SitewaertsDocumentViewer
.
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);
String pointing to a device local file (e.g. 'file:///...')
String representing the mime type of the file. Currently only 'application/pdf' is supported.
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
}
}
cordova.plugins.SitewaertsDocumentViewer.canViewDocument(
url, contentType, options, onPossible, onMissingApp, onImpossible, onError);
function onPossible(){
window.console.log('document can be shown');
//e.g. track document usage
}
function onMissingApp(appId, installer)
{
if(confirm("Do you want to install the free PDF Viewer App "
+ appId + " for Android?"))
{
installer();
}
}
function onImpossible(){
window.console.log('document cannot be shown');
//e.g. track document usage
}
function onError(error){
window.console.log(error);
alert("Sorry! Cannot show document.");
}
cordova.plugins.SitewaertsDocumentViewer.viewDocument(
url, mimeType, options, onShow, onClose, onMissingApp, onError, linkHandlers);
function onShow(){
window.console.log('document shown');
//e.g. track document usage
}
function onClose(){
window.console.log('document closed');
//e.g. remove temp files
}
function onMissingApp(appId, installer)
{
if(confirm("Do you want to install the free PDF Viewer App "
+ appId + " for Android?"))
{
installer();
}
}
function onError(error){
window.console.log(error);
alert("Sorry! Cannot view document.");
}
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);
}
}
];
cordova.plugins.SitewaertsDocumentViewer.closeDocument(onClose, onError);
function onClose(url){
if(url)
window.console.log('closed viewer document ' + url);
else
window.console.log('viewer not open');
}
function onError(error){
window.console.log(error);
alert("Sorry! Cannot close viewer.");
}
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.
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
The plugin uses
TODO
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
FAQs
PDF Document viewer cordova plugin for iOS, Android and Windows 8.1 + 10
The npm package cordova-plugin-document-viewer receives a total of 3,920 weekly downloads. As such, cordova-plugin-document-viewer popularity was classified as popular.
We found that cordova-plugin-document-viewer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.