[F/OS] Webview2File Extension: Effortlessly Convert WebView Content to Stunning PDFs and Gallery-Ready Images!

Webview2File Extension Documentation

Overview

The Webview2File extension allows App Inventor developers to easily convert the content of a WebView or WebViews inside a container into PDF files or images. The extension is designed for block programming and offers a straightforward way to manage WebView content as files.


Features

  • Convert WebView to PDF: Save the content of a WebView as a PDF file.
  • Convert WebView to Image: Save the WebView content as an image in the gallery.
  • Convert All WebViews in a Container to PDF: Process multiple WebViews within a container and generate individual PDF files.
  • Convert All WebViews in a Container to Images: Save the content of multiple WebViews as images.
  • Immediate Gallery Update: Automatically update the gallery when a file is saved.
  • Error Handling: Triggers events if errors occur during file generation.

Blocks Overview

Functions

1. ConvertToPDF

Converts the content of a single WebView to a PDF file.

Parameters:

  • WebViewer: The WebView component to process.
  • fileName: The name of the PDF file.

2. ConvertToImage

Converts the content of a single WebView to an image and saves it in the gallery.

Parameters:

  • WebViewer: The WebView component to process.
  • dirName: The name of the folder in the gallery where the image will be saved.

3. ConvertContainerToPDF

Converts the content of all WebViews within a container (e.g., HorizontalArrangement or VerticalArrangement) to PDF files.

Parameters:

  • Container: The container holding WebViews.
  • fileName: The base name for the generated PDF files. Each WebView will be saved as a separate PDF file with an index appended.

4. ConvertContainerToImages

Converts the content of all WebViews within a container to images and saves them in the gallery.

Parameters:

  • Container: The container holding WebViews.
  • dirName: The folder name in the gallery where the images will be saved.

Events

1. OnImageSaved

Triggered when an image is successfully saved to the gallery.

Parameter:

  • uri: The URI of the saved image.

2. OnPDFGenerated

Triggered when a PDF file is successfully generated.

Parameter:

  • message: A message indicating the success of the operation.

3. OnImageGenerated

Triggered when images from a container are successfully generated.

Parameter:

  • filePath: The path to the saved images.

4. OnError

Triggered when an error occurs during any operation.

Parameter:

  • message: A description of the error.

Usage Guide

Webview2File

Extension to convert WebView content to PDF and image.

Events:

OnImageSaved

OnImageSavedBlock

Triggered when the image is successfully saved to the gallery.

Parameter Type
uri text

OnPDFGenerated

OnPDFGeneratedBlock

Triggered when a PDF is generated.

Parameter Type
message text

OnImageGenerated

OnImageGeneratedBlock

Triggered when an image is generated.

Parameter Type
filePath text

OnError

OnErrorBlock

Triggered when an error occurs.

Parameter Type
message text

Methods:

ConvertToPDF

ConvertToPDFBlock

Converts the content of the WebView to a PDF file.

Parameter Type
webViewer component
fileName text

ConvertToImage

ConvertToImageBlock

Converts the content of the WebView to an image and saves it to the gallery.

Parameter Type
webViewComponent component
dirName text

ConvertContainerToPDF

ConvertContainerToPDFBlock

Converts the content of all WebViews within a container to a PDF file.

Parameter Type
containerComponent component
fileName text

ConvertContainerToImages

ConvertContainerToImagesBlock

Converts the content of all WebViews within a container to images and saves them to the gallery.

Parameter Type
containerComponent component
dirName text

This documentation was generated using Akshat Developer's Documentation Generator.


Notes

  1. Permissions: The extension requires storage access to save files. Make sure your app includes the necessary permissions.
  2. File Names: Ensure unique file names to avoid overwriting existing files.
  3. Gallery Update: Files saved as images are immediately visible in the gallery.

Files

AIX (by Fast Cli Builder): com.bosonshiggs.webview2file.aix (11.5 KB)
AIA: Webview2File.aia (14.0 KB)
Click Here and see the GitHub files!


Support

For additional help or questions, please visit the community forum or contact support. Happy coding! :rocket:

6 Likes

Please add photos of blocks, not just in text.

1 Like

At the end of the text there are blocks

There are only 2 blocks in this extension?

1 Like

How does the extension handle file paths when saving an image? Please show explained examples.

Not saving an image with any path I try.

In addition, where does one assign a filename to the image ?

1 Like

Until all existing blocks are shown/explained and bugs in the .ConvertToImage method are fixed, I will unlist the topic.

1 Like

Are you using any library in this extension? If yes, provide a link to the library to credit its author

Taifun

1 Like

I will check the bug and release the code on GitHub

Didn't you test your aia beforehand?

1 Like

Yes, I tested it.

And it works? If so, on which device & Android version?

I just saw here, I will send the correct AIA.

There are no external libraries. Please test the new AIA and AIX files attached in the text.

Where, in the first post ? These have been updated ?

1 Like

Yes, the original post has been updated.

Where should the image be saved?

I tested it and had no problems. Did you use the AIA from the original post?

Either way it's an operation that requires operations that modify the user interface (like drawing on a WebView) to be performed on the main thread. I'll update.

New Files

AIX (by Fast Cli Builder): com.bosonshiggs.webview2file.aix (10.7 KB)
AIA: Webview2File.aia (13.3 KB)
Click Here and see the GitHub files!