📚 [Free] ViewPDF - a simple pdf viewer for local files

1. Introduction

I was doing some work with @Juan_Antonio's KIO4_PDF extension and realised that it was possible to view ANY pdf available on the device (within reason, depending on location, Android version / API). I came up with some blocks to make it possible to view an entire pdf in a webviewer. (There are already straightforward methods for viewing pdfs locally and from online resources)

In discussion with Juan, and with his help and code, I then developed this extension which would do the same thing. There is no set path to the pdf, so the developer will need to use the getAPI block and getASD block (if needed) for version testing and application. However, once compiled, you would need to copy your pdf asset across to your ASD in order to view it in Android > 9.

The extension requires a webviewer to display the pdf.
I am not sure what would happen with really large or really long pdf files... :wink:

  • Latest version: 2.4
  • Tested: tested on App inventor 2 (n188), in companion (2.62u) and compiled modes on Android 10 and Android 12. (Also tested on Android 7 companion)
  • Released: 2021-10-23T23:00:00Z
  • Last updated: 2021-11-20T00:00:00Z
  • Built: using the RUSH Extension Builder by @Shreyash

2. Blocks (v2.4)

viewpdf2_4ExtBlocks

3. Usage v2.3
(testing in companion Android>9)


(testing in companion Android<10)

(copy file in assets to ASD, seems to work for all Android versions that have an ASD)

(view pdf from ASD)

(html colour properties)

Usage v2.4

3. Files
v2.3 for simple viewing
AIX: uk.co.metricrat.viewpdfv2_3.aix (17.5 KB)
v2.4 for interaction - select page number, scroll to page number, return page count
AIX: uk.co.metricrat.viewpdfv2_4.aix (18.1 KB)

4. Changelog

  • 2.1
    • first release
  • 2.2
    • added background colour for html property
    • added text colour for page numbers property
    • (for both the above set to -1 to return to default)
    • changed copyFromAssets >> copyFromAssetsToAsd
    • added routine to delete the temporary html file on exit
  • 2.3
    • update to provide webviewer file access on kodular
  • 2.4
    • added page count property
    • added page clicked returns page number to webviewstring
    • added scroll to page number from webviewstring
    • developer must set webviewstring = 1 when first displaying pdf
    • no requirement to reload pdf when changing scroll to page

5. Credits
My thanks to @Juan_Antonio, whose KIO4_PDF extension work has made this all possible.
Thanks to @vknow360 for his help with the update for file access

PDFs from MIT CTCT Curriculum, Hello It's Me, Karen Lang (copyright MIT 2021)

6. Video Demo

Enjoy :smiley: , and all feedback and comments welcome.

Available for use in any MIT AppInventor projects or competitions

16 Likes

Good job. Would it make sense to call the CopyFromAssets CopyFromAssetsToAsd since that is where it is going?

2 Likes

Will add to list for updates. The tooltip does tell you though

image

3 Likes

Instead why not take an arrangement, create a new web view and display it?

1 Like

Then it would require an arrangement instead of a webviewer :wink:

3 Likes

Very good extension @TIMAI2

1 Like

1 Like

Update to v2.2

  • adds colour properties for html background and text
  • edit to copyfromAssets block title
  • temp file delete function added (under the hood...)
3 Likes

Doesn't seem to work with Kodular.

1 Like

Any of it, or just one of the functions ?

1 Like

The web page at

file:///data/user/0/io.makeroid.companion/cache/display4036312430542112567.html

could not be loaded because

net:ERR_ACCESS_DENIED

1 Like

We believe it is a file path issue, peculiar to Kodular. Will have a look at it.

1 Like

@Anke

Did you try a compiled app?

1 Like

Same result.

1 Like

Good job @TIMAI2, great PDF reader!

2 Likes

updated to v2.3 to provide file access in Kodular

2 Likes

updated to version 2.4

new features:

  • added page count property
  • added page clicked returns page number to webviewstring
  • added scroll to page number from webviewstring
  • developer must set webviewstring = 1 when first displaying pdf
  • no requirement to reload pdf when changing scroll to page
1 Like