Code Monster
Code Monster

Reputation: 27

PDFTron Android Sample PDF

Using the Android sample in the WebViewer folder I have an application in Android Studio which when run on my device works and displays the xod file given as expected. However I've tried to change the lines:

String documentPath = getFilesDir().getPath() + "/GettingStarted.xod";
InputStream in = getAssets().open("xod/GettingStarted.xod");

to

String documentPath = getFilesDir().getPath() + "/sample.pdf";
InputStream in = getAssets().open("xod/sample.pdf");

And have also changed the endsWith(".xod") to endsWith(".pdf") but I only get a grey screen. For this to work does the file have to be a .xod? As it works for xod files but not pdf files.

Thanks for your time.

Upvotes: 0

Views: 488

Answers (1)

Ryan
Ryan

Reputation: 2560

Yes, for mobile viewing you need to convert your files to the web-optimized XOD format.

The PDF backend for WebViewer is not available for mobile browsers. This is due to limitations of the hardware and the mobile browsers.


For desktop browsers, to switch from XOD backend to PDF backend, you need to follow the steps. See here for more details, especially if you run into any errors.

var myWebViewer = new PDFTron.WebViewer({
    path: "lib",
    type: "html5",
    documentType: "pdf",
    initialDoc: "GettingStarted.pdf"
}, viewerElement);

Notice the documentType parameter is set to pdf.

Upvotes: 1

Related Questions