0

I am trying to display the PDF file from apache tomcat using IBM Worklight. Using the following link Worklight Adapter getting pdf file from rest service, i converted the PDF file into Byte Array.
In the client side, the code is

var pdfText = decodeURIComponent(response.invocationResult.pdf);
var pdf = base64DecToArr(pdfText);
PDFJS.getDocument(pdf).then(iterate);

But i am unable to display the file. When running the following code on emulator, it is not displaying any error. When running the same code in chrome browser, Error: Invalid XRef stream header util.js:186 at error Warning: Unsupported feature "unknown" util.js:171 Warning: Unsupported feature "unknown" util.js:171 Warning: Indexing all PDF objects

I need to know how to display the [Object Uint8Array] as PDF.

Community
  • 1
  • 1
sasi
  • 512
  • 4
  • 27

1 Answers1

0

Android has no native PDf viewer capability in their browser (unlike Safari in iOS), so simply receiving a PDF and converting/opening it in the webview isn't going to work.

Two options from here: Phonegap InAppBrowser display pdf 2.7.0

  1. Don't download the PDF; instead redirect to the online view capabilities of Google Doc Viewer, as stated in this StackOverflow answer

  2. Download the file and use the FileOpener Cordova plug-in. This will either open the file in an installed PDF reader app or present the user with a choice.

You could also always opt to write your own custom Cordova plug-in(Getting Started training module) in Worklight that will implement some native code to view PDFs in Android.

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • I am getting the pdf file as [Object Uint8Array] through rest services only, as i mentioned in the question. In that case, how can i pass the [Object Uint8Array] to display as a pdf file using javascript or any other 3rd party plugin. – sasi Jun 13 '14 at 05:16
  • Read the Cordova plug-in training modules I linked to... the API allows to send data to the plug-in. – Idan Adar Jun 13 '14 at 05:17