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.
- 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.
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.
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.
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.
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.
Triggered when an image is successfully saved to the gallery.
Parameter:
uri
: The URI of the saved image.
Triggered when a PDF file is successfully generated.
Parameter:
message
: A message indicating the success of the operation.
Triggered when images from a container are successfully generated.
Parameter:
filePath
: The path to the saved images.
Triggered when an error occurs during any operation.
Parameter:
message
: A description of the error.
- Drag and drop a WebViewer component into your screen.
- Set up the WebViewer to load your desired content.
- Use the ConvertToPDF block to generate a PDF:
call Webview2File.ConvertToPDF(WebViewer1, "MyDocument.pdf")
- Set up your WebViewer as described above.
- Use the ConvertToImage block:
call Webview2File.ConvertToImage(WebViewer1, "MyImages")
- Place multiple WebViewer components inside a container (e.g., HorizontalArrangement).
- Use the ConvertContainerToPDF block:
call Webview2File.ConvertContainerToPDF(HorizontalArrangement1, "ContainerPDF")
- Set up your WebView components inside a container as described above.
- Use the ConvertContainerToImages block:
call Webview2File.ConvertContainerToImages(HorizontalArrangement1, "GalleryFolder")
- Drag a WebViewer component into your app.
- Load the webpage:
set WebViewer1.Url to "https://example.com"
- Convert the content to a PDF:
call Webview2File.ConvertToPDF(WebViewer1, "ExamplePage.pdf")
- Permissions: The extension requires storage access to save files. Make sure your app includes the necessary permissions.
- File Names: Ensure unique file names to avoid overwriting existing files.
- Gallery Update: Files saved as images are immediately visible in the gallery.
For additional help or questions, please visit the community forum or contact support. Happy coding! 🚀