How can I load a local HTML or PDF file?

With 3D WebView for Unity, you can load local HTML and PDF files from the file system using a couple of different approaches:

Load a local file from StreamingAssets

The easiest way to add local HTML and PDF files to a Unity project is to place them in the project's StreamingAssets folder, like this:

  1. Create the following directory in your project: Assets/StreamingAssets
  2. Copy your web page resources to the StreamingAssets folder. For example, you could have a folder with the following files:
    • Assets/StreamingAssets/index.html
    • Assets/StreamingAssets/styles.css
    • Assets/StreamingAssets/index.js
  3. Tell 3D WebView to load the HTML file in StreamingAssets by passing it a streaming-assets:// URL. For example, to load the file at Assets/StreamingAssets/index.html, you would use the URL streaming-assets://index.html. You can specify the URL by changing the WebViewPrefab's Initial URL field in the editor or by passing it to IWebView.LoadUrl() at runtime, like this:
await webViewPrefab.WaitUntilInitialized();

For an example of this approach, please see this blog article on creating UIs with HTML.

Load a local file from other locations

If you want to load a local file from a different location, you can use a file:// URL instead. For example, here's how you could load a file from Application.persistentDataPath:

await webViewPrefab.WaitUntilInitialized();
var filePath = $"{Application.persistentDataPath}/myfile.html";
// Spaces in URLs must be escaped
var fileUrl = "file://" + filePath.Replace(" ", "%20");

All 3D WebView packages support loading files from StreamingAssets, but on sandboxed platforms like Android, iOS, and UWP, the browser engines disallow loading web pages from some directories. So, if you find that the browser is failing to load your file URL, you can use remote debugging and view the application logs to check if the browser is blocking the local file from being loaded.