This is the reply of claude sonnet 5.5 AI to the same request ( claude does a better job, after minor corrections, and uses no extension/library ):
I’ll build the single HTML file first. The PDF writer is plain JavaScript with no external library, so it works fully offline.
I’ve written form.html (attached) and tested its PDF generator: it produced a valid 2-page PDF made only of plain ASCII characters. I haven’t run the App Inventor side, so test that part on your tablet.
How it works
- The form is built from a JSON block at the top of the file. You add, remove or rename fields there and nothing else changes.
- When you tap Export, JavaScript builds the PDF itself, with no library and no internet, and it can run several pages.
- Umlauts and similar characters are written as escape codes, so the whole PDF is plain ASCII text. That lets App Inventor save it with its normal File component, with no extension needed.
- JavaScript hands the PDF to App Inventor with
AppInventor.setWebViewString("PDF|filename|data"). The blocks then write it to a file.
In a normal browser, the same button downloads the PDF instead, so you can test the form on a PC first.
Step 1: Project setup
- Upload
form.html under Media in the Designer.
- Add these components to Screen1:
- WebViewer1 (Height and Width: Fill parent)
- Clock1 (TimerInterval =
500, TimerEnabled = true, TimerAlwaysFires = false)
- File1 (Scope =
Shared)
- Notifier1
- Sharing1 (optional, to open the PDF afterwards)
Step 2: Blocks
Global variables: create parts, fileName and pdfText, each initialised to an empty text.
A. Load the page
when Screen1.Initialize
do call WebViewer1.GoToUrl
url: "file:///android_asset/form.html"
For live testing with the Companion app, use file:///mnt/sdcard/AppInventor/assets/form.html instead.
B. Check for an export (App Inventor has no “string changed” event, so a timer polls)
when Clock1.Timer
do if (starts at text: WebViewer1.WebViewString piece: "PDF|") = 1
then
set global parts to split text: WebViewer1.WebViewString at: "|"
set global fileName to select list item list: global parts index: 2
set global pdfText to uri decode (select list item list: global parts index: 3)
set WebViewer1.WebViewString to "" ← prevents saving twice
call File1.SaveFile
text: global pdfText
fileName: join( "Download/", global fileName )
The uri decode block is in the Text drawer.
C. Confirm the save
when File1.AfterFileSaved (fileName)
do call Notifier1.ShowAlert notice: join("PDF saved: ", fileName)
(optional) call Sharing1.ShareFile file: fileName
D. Errors
when Screen1.ErrorOccurred (component, functionName, errorNumber, message)
do call Notifier1.ShowAlert notice: message
Step 3: Build and test
Use Build → Android App (.apk) and install it on the tablet. Saving to shared folders can be restricted in the Companion app on newer Android versions, so the compiled app is the reliable test. Fill in the form, tap Export, and the alert shows the real save path.
Things to check
- Save location: with
Scope = Shared, Download/name.pdf should land in the tablet’s Downloads folder. If your build rejects it, try /Download/name.pdf. As a fallback, set Scope = App and use only name.pdf: the file then sits in the app’s own folder, and Sharing1.ShareFile lets the user open or copy it.
- Fonts: the PDF uses Helvetica, so Latin characters (including ä, ö, ü, é, €) work. Other scripts, such as Cyrillic or Chinese, would need an embedded font.
- Line wrapping: the wrapping uses an estimated character width, so very wide capital letters may run slightly close to the right margin.
- Size: very long texts are fine, but the whole PDF travels as one string. Keep it to a few hundred KB at most.
If you tell me which fields you need, I can adjust the JSON block. I can also draw the blocks as an image if that would make them easier to build.
form.txt (7.8 KB)