Skip to content

Latest commit

 

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdfView for Android and iOS

Module for display pdf in a view in titanium, with zoom + scroll.

Uses AndroidPdfViewer on Android and PDFKit (PDFView) on iOS.

Module Naming

fr.squirrel.pdfview

Requirements (Android):

  • Titanium 13.3.0
  • add the following lines to your app/platform/android/build.gradle file:
repositories {
	maven { url 'https://jitpack.io' }
}

Requirements (iOS):

  • Titanium 13.3.0.GA+
  • iOS 12+

Example usage

Load a pdf with "url" property

var pdfView = require("fr.squirrel.pdfview").createView({
 height : Ti.UI.FILL,
 width : Ti.UI.FILL,
 url : "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
});
$.container.add(pdfView);

Or by "file" property

 var downloadingFileUrl = "https://monurl/sample.pdf"
 var file = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory,"./sample.pdf");
 var httpC = Ti.Network.createHTTPClient();

 httpC.onload = function(httpClient){

  var pdfView = require("fr.squirrel.pdfview").createView({
    height : Ti.UI.FILL,
    width : Ti.UI.FILL,
    file : file
  });
  $.container.add(pdfView);
 };
 httpC.open("GET", downloadingFileUrl);
 httpC.setFile(file.getNativePath());
 httpC.send(null);

opening a password protected local file

const win = Ti.UI.createWindow();

var file = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, "pwd.pdf");

if (!file.exists()) {
	// copy it from /assets/ to the external storage
	var source = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "pwd.pdf");
	file.write(source.read());
}

var pdfView = require("fr.squirrel.pdfview").createView({
	height: Ti.UI.FILL,
	width: Ti.UI.FILL,
	password: "yourPassword",
	file: file
});

win.add(pdfView);
win.open();

Properties

  • url (string) : this property is for load a pdf directly by url.
  • file (Ti.Filesystem.File or Ti.Blob) : this property is for load a pdf directly by a file.
  • spacing : this property is for edit the spacing between pages in dp.
  • password (string) : password for a protected PDF file
  • nightMode (boolean) : night mode (iOS: only darkens the background, page content is not inverted)
  • pageFling (boolean) : make a fling change only a single page like ViewPager
  • pageSnap (boolean) : snap pages to screen boundaries at the end of a scroll
  • swipeHorizontal (boolean) : horizontal swipe
  • minZoom (float) : sets min zoom level (default 1)
  • midZoom (float) : sets mid zoom level (default 1.75, Android only)
  • maxZoom (float) : sets max zoom level (default 3)
  • nestedScrolling (boolean) : enabled nested srcolling (default: false, Android only)
  • pageNumber (int) : sets the initial page number to display (default 0). Number is the page index starting with 0 (page 1).
  • textSelection (boolean) : allow selecting text in the PDF with a long-press (default: false, iOS only - Android renders pages as bitmaps and has no text selection). When enabled, a long-press on text starts the selection and fires the longpress event; keep it disabled if you only want the event.

Events

  • error: with message, passwordError (true if password is wrong)
  • pageChanged: fired when the displayed page changes, with currentPage (0-based page index) and pageCount (total number of pages)
  • link: fired when a link inside the PDF is tapped, with url (the link is not opened automatically)
  • longpress: fired when the user long-presses the PDF, with x and y (view-relative coordinates in dp/points). If the press hits a link inside the PDF, url contains its target (otherwise url is not set).
pdfView.addEventListener("longpress", function(e) {
	if (e.url) {
		console.log("longpress on link " + e.url);
	} else {
		console.log("longpress at " + e.x + "/" + e.y);
	}
});

Methods

  • clear(): clear the pdfview

About

A module to display a PDF in a view on Android

Resources

Stars

11 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages