Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ibrahimAlfors · Jun 09, 2014 at 06:11 PM · androidioswwwpdf

Open a PDF on Android and iOS

Okay this has been haunting me for a couple of days, I have this project one of its features is that it would have this button that would open a local pdf file for the user. However, the project is intended for Android and iOS.

What I achieved so far is locating the pdf file from the .apk on android (I haven't tested it on iOS yet). I used the WWW class to do so, and I checked for the size and it returned the true size of the PDF (Which proves that I have the correct file).

The problem is that I can only access the file through the WWW class (to get the size for example), How do I open it through www.assetBundle.mainAsset?

My thoughts were that I should first save the pdf file in a temporary location and use the OpenURL or maybe the process.start to open it. But I can't figure out how to do that either.

I have done tones of research and got this far and I can't find anything online that would help me to take this last step, so if anyone can help me with it, please tell me.

Thanks

EDIT: The code I used is

 IEnumerator Start() {
         if(Application.platform == RuntimePlatform.Android){
             path =Application.streamingAssetsPath + "/The_100.pdf";
         }else{
             path = "file://"+Application.streamingAssetsPath + "/The_100.pdf";
         }
         WWW www = new WWW(path);
         yield return www;
 }

when I use www.size it returns the correct size of the pdf file

Comment
Add comment · Show 3
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
avatar image Giantbean · Jun 10, 2014 at 04:42 PM 0
Share

I would like to add to this conversation as I am fighting the same issue with loading a PDF on Android. The documentation on data paths does not mention Android and strea$$anonymous$$g assets gives a path that I have not been able to get working.

 path = "jar:file://" + Application.dataPath + "!/assets/" + "filename";

Then they suggest the WWW load method in application strea$$anonymous$$g assets

It seems you have to use the jar path with the WWW but I'm not sure how. Another Question has some ideas but it is still unclear. Android can play video full screen with.

 Handheld.PlayFullScreen$$anonymous$$ovie ("filename", Color.black, FullScreen$$anonymous$$ovieControl$$anonymous$$ode.CancelOnInput);

but PDF files wont load using Application.OpenURL(Jar path...

Has anyone been able to load a PDF on an Android?

avatar image Giantbean · Jun 11, 2014 at 05:34 PM 0
Share

I ended up faking it with NGUI plugin however you may also want to check out this thread or if the device will have a network conection you can count on you can still use

Application.OpenURL("web pdf address");

Good luck to you.

avatar image ibrahimAlfors · Jun 14, 2014 at 10:21 AM 0
Share

Thanks :) its a good idea but my problem is that the only way I can access this pdf file is through the www class and I don't know how to add a reference to it, like object pdfObject = (Object) www.assetBundle.mainAsset; I have tried that and it didn't work but you get the idea of what I want

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by ibrahimAlfors · Jun 14, 2014 at 02:49 PM

I have figured out how to save the file to the Application.persistentDataPath The code I used:

     IEnumerator Start() {
         if(Application.platform == RuntimePlatform.Android){
             path =Application.streamingAssetsPath + "/The_100.pdf";
             savePath = Application.persistentDataPath;
         }else{
             path = "file://"+Application.streamingAssetsPath + "/The_100.pdf";
             savePath = "C:/Users/IBRAHI/Desktop/SaveTestUnity";
         }
         WWW www = new WWW(path);
         yield return www;
         error = www.error;
 
         byte[] bytes = www.bytes;
         result = "Done, bytes downloaded, File size : "+bytes.Length;
         try{
             File.WriteAllBytes(savePath+"/The_100.pdf", bytes);
             error = "No Errors so far";
         }catch(Exception ex){
             error = ex.Message;
         }
         Application.OpenURL(savePath+"/The_100.pdf");
     }

Thanks

Comment
Add comment · Show 1 · Share
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
avatar image nicloay · Dec 21, 2015 at 07:07 AM 0
Share

thanks for code. works for me as well.

avatar image
-1

Answer by SlavaObninsk · Jan 31, 2015 at 05:16 PM

PDFReader available on the AssetStore http://u3d.as/7AX

Comment
Add comment · Share
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

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

24 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

Related Questions

Handheld.PlayFullScreenMovie() works on Android but not iOS? 2 Answers

WWW http request loads way to long on IOS 0 Answers

IOS http request loads slower at the first call of the scene 0 Answers

how to delete specific files from cache? 3 Answers

Android multiple WWW freezes 0 Answers


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