Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

View PDF File in Unity iOS

Discussion in 'Scripting' started by siddharth3322, Apr 9, 2018.

  1. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    I want to open and view PDF file in iOS project. Following kind of code, I have tried upto now:

    Code (CSharp):
    1. public void OnDel1ButtonClick ()
    2.     {
    3.         Application.OpenURL ("file://" + Application.streamingAssetsPath + "/Del1.pdf");
    4.     }
    5.  
    6.     public void OnDel2ButtonClick ()
    7.     {
    8.         Application.OpenURL(Application.dataPath + "/Raw/Del1.pdf" );
    9. //        Application.OpenURL ("file:///" + Application.streamingAssetsPath + "Del1.pdf");
    10.     }
    I have placed PDF file in Streaming Assets folder like this:

    streaming_assets_pdf.png

    Within Unity Editor, first button click event is working but within actual iPhone device none of the above ways are working. So give me some suggestion to open and view PDF file.

    If any kind of permission, I was missing then also let me know about this. I have referred this document upto now:

    https://docs.unity3d.com/Manual/StreamingAssets.html
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    The OpenURL will only be able to handle https:// and http:// style addresses but it looks like you're using file://
     
  3. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    Any way exist to view PDF files in iOS?
     
  4. is_it_tennant

    is_it_tennant

    Joined:
    May 22, 2018
    Posts:
    1
    Well, the answer provided by Kurt above is 100% true, there is no way to put there a path to the file system of your device. Did you ever try to send to somebody link to the file from your laptop with the path C:\ ? :) In order to make this piece work, you should host your file somewhere and share its path here. It's easy to do through this tool https://pump-it-up-job-form.pdffiller.com/ so you'll be able to upload your form as well as to make some amends and add your signature. Do hope this will be helpful
     
  5. unclebob301

    unclebob301

    Joined:
    Jan 29, 2014
    Posts:
    20
    Interesting.

    You can use Application.OpenURL (https://docs.unity3d.com/ScriptReference/Application.OpenURL.html) and pass the pdf location url with page numbers or destinations as covered here in the adobe documentation https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters_v9.pdf

    Using a hosted pdf means that you can open on specific pages or destinations within the document if already defined.

    Note that you are limited to opening the file directly not at a specific destination within the pdf if you use local hard drive addresses (c:\folder\).

    To test on a PC use file:/// as using file:// does not work and always catches people out.
    Such as
    file:///C:/Users/Yourname/Documents/1.pdf

    Hope this helps