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 Fanny · Feb 23, 2013 at 10:24 AM · c#iospdf

Opening a pdf file on iOS devices is failed

Hello there,

I am developing an app on both Android and iOS devices (says, iPhone and iPad). Some functions work well on Android devices (where I build them on Windows 7): opening a PDF file and uploading screen shots. Here I mainly ask a solution to open the PDF file on iOS devices.

Here are what I have done and what the code (C#) works well on Android devices:

  1. The PDF file 'manual.pdf' is initially put in the 'Resources' folder (in Unity editor).

  2. I change the file extension of the PDF file from 'pdf' to 'bytes'

  3. When the function to load the PDF file is triggered, I load this file using the code:

    TextAsset manual = Resources.Load("manual", typeof(TextAsset)) as TextAsset;

  4. The 'TextAsset manual' is then saved as a PDF file on the devices:

    System.IO.File.WriteAllBytes(Application.persistentDataPath + "/manual.pdf", manual.bytes);

  5. I also tried this pieces of codes on iOS devices:

    string path = System.IO.Path.Combine(Application.persistentDataPath, "manual.pdf");

    FileStream fs = new FileStream(path, FileMode.Create);

    BinaryWriter w = new BinaryWriter(fs);

    w.Write(manual.bytes);

    w.Close();

    fs.Close();

  6. Then load the PDF file which was just saved onto the devices; I tried these codes:

    Application.OpenURL(path);

    Application.OpenURL("file://"+path);

    Application.OpenURL("file:///"+path);


The above is what I have done and works well on Android devices, but not works on iOS devices at all (tested on new iPad).

Some questions I would like to ask:

  1. Is there any better method to save the PDF file onto the devices when the app is installed?

  2. I found that if one wants to open Facebook page using Facebook app, one should call OpenURL with the parameter: "fb://xxx...". Does it have the similar way to open a pdf file?

  3. I am wondering if there is something wrong with these codes? The codes work well on Android devices and even on Mac's Unity to test it directly. Maybe I have to do some modifications on Build Settings?

Hopefully some people can provide me suggestions! Thank you.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xwx217 · May 27, 2014 at 06:49 AM

Hi! I want to write a function to open a pdf(that have build with the app) on the android platform.I googled your answer, see you use this code work well , So I write like this ,but it does't work ,is something i did't done,So I hope you can give me a help! Thinks a lot! this is my code:

using UnityEngine; using System.Collections; using System.IO; .... ... TextAsset pdf = Resources.Load("pdf", typeof(TextAsset)) as TextAsset; System.IO.File.WriteAllBytes(Application.persistentDataPath + "/pdf.pdf",pdf.bytes); string path = System.IO.Path.Combine(Application.persistentDataPath,"pdf.pdf"); System.IO.FileStream fs =new System.IO.FileStream(path,System.IO.FileMode.Create);
BinaryWriter w= new BinaryWriter(fs); w.Write(pdf.bytes); w.Close(); fs.Close(); // 加载PDF文档 Application.OpenURL(path); Application.OpenURL("file://"+path); Application.OpenURL("file:///"+path);

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Q about Building my game for so many devices 2 Answers

Detect RAM usage of program 0 Answers

UDPSend not working with iPad over LAN 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