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

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: - see Post 42 for update on a second extension that handles large files

  • Latest version: 2.5
  • 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: 2024-03-31T23:00:00Z
  • Built: using the RUSH Extension Builder by @shreyash

2022-02-25T00:00:00Z

  • Now added a ViewPdfAddOn which contains a single block for reading in pdf files from Assets when the app is compiled

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

Usage v2.5

3. Files

AIX: ViewPDF

AIX: ViewBigPDF

4. Changelog

  • 2.1
    • first release
  • 2.2
    • added background colour for html property (Use -2 if you want a white background, the colour block does not work)
    • 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
  • 2.5
    • added quality option, 0 - 10, where 0 is the default
    • pdfaddon function now included in main extension (for loading pdfs from assets when compiled)
    • AfterDisplay event added, to allow for actions once pdf is rendered and displayed (useful for progress dialog when loading large pdfs - in testing, with quality setting at 10, a 100 page pdf took @ 30 seconds to render)

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

#####################################################################
This work by TIMAI2 is licensed under a
Creative Commons Attribution-ShareAlike 4.0 Unported License with attribution.
Please use name = TIMAI2 and link to this source page when giving credit.
#####################################################################

23 Likes

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

4 Likes

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

image

4 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:

4 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...)
4 Likes

Doesn't seem to work with Kodular.

1 Like

Any of it, or just one of the functions ?

2 Likes

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.

2 Likes

@Anke

Did you try a compiled app?

2 Likes

Same result.

1 Like

Good job @TIMAI2, great PDF reader!

2 Likes

updated to v2.3 to provide file access in Kodular

3 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
2 Likes

Update:

Now included is an add on extension to allow selection of Assets when the app is compiled. The method used to do this is to write(copy) the asset file to a temporary file in the private directory of the app (there doesn't really appear to be any other way at the time of writing). The temporary file is overwritten when a new asset is loaded. You must ensure that your file naming follows the standard format, e.g. myfile.pdf

You can download the add on extension and see the usage/blocks in the first post.

ViewPdfAddOn extension

1 Like

Hi @TIMAI2 , hope you are having a good time, I wanted to ask that, what block fitts in the web viewer socket in this block if we want to open a specific PDF.
image
I would be highly grateful if you answer this question

Arnav Tiwari

check 1st post, there is sample blocks there.

2 Likes