See the App Inventor Extensions document about how to use an App Inventor Extension.
For questions about this extension or bug reports please start a new thread in the
App Inventor community. Thank you.
For feature requests please contact me by email.
To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.
Nov 14th, 2016: Initial Version 1
Nov 19th, 2016: Version 1a: bug fixes
Oct 25th, 2017: Version 1b-e: new properties render mode, quailty, rendered filename added
Mar 5th, 2018: Version 2: new property hasAlpha added, see also this discussion
Mar 24th, 2021: Version 2a: Android Min SDK set to 21, rendered file will now be stored in the ASD, no WRITE_EXTERNAL_STORAGE permission required anymore, Android 10 update concerning asset path for companion app, Android 11 update concerning READ_EXTERNAL_STORAGE for SDK29
Sep 6th, 2023: Version 3: PickAndOpen method added to pick and open a pdf file from shared storage, helper blocks added for RenderMode property, HtmlPage property added to display the rendered pdf page in a html page stored in ASD, example app updated to 1) provide the pdf page zoomed out, added swipe feature to swipe to next/previous page
Nov 1st, 2023: Version 3a: up and down swipe detection added, border removed in pdf
Extension to open pdf files and render a specific page (without using an external app).
Required permissions: android.permission.READ_EXTERNAL_STORAGE
Minimum API level of this extension is 21 (Android 5)!
Returns whether Warnings should be suppressed
Specifies whether Warnings should be suppressed
Returns the number of pages
Set the quality in dpi to render the pdf page. Default is 72 dpi.
Set render mode (DISPLAY or PRINT). Default is DISPLAY.
helper blocks added
Has alpha (true or false), i.e. if the pixels may contain non-opaque alpha values. Default is false.
Setting this property to true will convert a transparent background into white.
Returns html page
Open a pdf file.
Prefix the pdfFilename with / (i.e. relative path) to open a pdf file from the SD card.
For instance /Download/myFile.pdf will open the file /storage/emulated/0/Download/myFile.pdf.
This works only, if the pdf is owned by your app. In case it is not owned by your app,
use the PickAndOpen method to first pick a file from shared storage and then open it.
To open a pdf file from the assets packaged with an application (also works for the Companion)
start the pdfFileName with // (two slashes).
Note: spaces in the pdf file name are not allowed!
Pick and open a pdf file from shared storage, which is not necessarily owned by your app.
Render a specific page.
Event indicating that pdf file was opened.
If the pdf file was opened successfully, the flag 'successful' is true and
the pdfFileName is provided in the response. In case of an error,
flag 'successful' is false and the error message is provided in the response.
The example offers the possibility to pick a pdf file from the assets or shared storage, renders a specific page
and displays it in the webviewer to be able to zoom in/zoom out and swipe to next/previous page.
In case you don't need zoom functionality or swipe feature, use an image component instead of the webviewer.
The example app uses a html file stored in the assets of the extension. This file will be copied to ASD to display the rendered page of the pdf file.
Alternatively you can display the rendered pdf file in an image component. See Q4 below.
Version 3 tested successfully on Nexus 5X running Android 8.1 and Samsung Galaxy A54 running Android 13. Version 3 has only been tested using App Inventor, but not in other distributions like Kodular or Niotron.
Q1: Does this extension work if I provide the full path of the location of the PFD file? For instance, this path: /storage/emulated/0/Download/filename.pdf?
Why? Because I want to use your extension with the FileChooser Extension by ILoveThunkable. And the file chooser extension only provides the full path.
A: You can specify a complete path to the pdf file. Example: file:///storage/emulated/0/Download/filename.pdf.
This path to a file in shared storage will work only if the app does have access to that file. If not, then use the new PickAndOpen method from version 3.
Q2: Does PDF reader swipe to go to next page feature there?
A: Yes, this feature has been implemented in version 3.
Q3: Just I noticed from the demo apk of PDF ext (version 2) that when I open the PDF it is zoomed and I need to zoom out. How I can set it by default to no zoom when the PDF is opened?
A: This has been fixed in the example app of version 3.
Q4: I can not do a simple test for what I want to do. Can you give me a simple example with: when I click on the button1, display a PDF?
A: Here are the blocks for a simple example to open a one page pdf file to display it in an image component:
The test app is available in Google Play. You can test the example following these steps
Note: Minimum API level of this extension is 21 (Android 5)!
You can buy this extension (aix file).
With your payment you accept the
terms and conditions below.
Payment options
1.
Please transfer 12 USD via Paypal
to Pura Vida Apps
2.
After having received your payment I will be happy to send the download link to you. Please let me know your Google account!
I usually will send the download link not later than 24 hours after having received your payment.
Thank you! Taifun