- Home /
How to open PDF on particular page on Android?
Hello, I'm trying to open LOCAL PDF file on concrete page on Android. I've tried few options, but I didn't make it happen. It has to be offline application, so I cannot use any http links. To download the PDF.
1) I placed test.pdf in my StreamingAssets, copied to persistentDataPath and opened with
Application.OpenURL(Application.persistentDataPath + "/test.pdf");
This worked without a problem, but opened only on page 1. If I try to add selector #page=5 at the end, it doesn't open at all
2) I found here, that it's possible to open .html file and then with script load .pdf, placed near the .html. I managed to open html file with this:
IEnumerator OpenMainRoutine()
{
string path = GetStreamingAssetsPath() + "pdfloader.html";
WWW www = new WWW(path);
while (!www.isDone)
{
yield return new WaitForEndOfFrame();
}
string persistentPath = Application.persistentDataPath + "/" + "pdfloader.html";
File.WriteAllBytes(persistentPath, www.bytes);
Application.OpenURL(persistentPath);
}
In pdfloader.html I have this code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function load () {
//window.location.href = "test.pdf#page=5";
alert("LOADED!");
}
</script>
</head>
<body onload="load()">
<h1>Test PDF</h1>
<a href="./test.pdf#page=5">GO TO PDF</a>
<script type="text/javascript">
alert("LOADED!");
</script>
</body>
</html>
With this solution I have following problems.
Opening with link (a href..) doesn't work at all (does nothing, browser shows short loading, but does nothing)
Opening with any script (like window.location) is impossible, because script is never executed, not even alerts etc.
I noticed one thing when testing this on real device. All remote sites (opened with http or https) are opened with Chrome browser, but local HTML file opened with Application.OpenURL() is opened with HTML Viewer. That might be the issue, why its not working. Is there any way to force to open it with Chrome browser? Or at least default one?
Or is there any other solution to open PDF like this? I saw some plugin to render PDF directly in scene on AssetStore, but it's quite expensive
Your answer
Follow this Question
Related Questions
Unity iOS Android: open local HTML in Browser 1 Answer
How to open a pdf on android device from streaming assets folder 4 Answers
How to open file with external app android 4 Answers
Saving login info locally Android iPhone 0 Answers
How to find list of files in "StreamingAssets" folder in Android 1 Answer