Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by vratislavino · Aug 15, 2018 at 05:38 PM · androidlocalhtmlstreamingassetspdf

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

206 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges