Search Unity

Load PDF from Unity iOS

Discussion in 'Scripting' started by jsr2k1, Apr 18, 2011.

  1. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Hello,

    Is it possible to load a LOCAL pdf in safari from an iOS project?
    I tried to load it with Application.OpenURL(file:///...../myFile.pdf) but it has no effect.
    I think it's for security, but I can load a local html in Android, then why not in iOS?

    Joel
     
    Last edited: Apr 18, 2011
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unity has no PDF importing or rendering, so there's not really anything you can do with it anyway. (Short of writing your own importer.)

    --Eric
     
  3. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    What I want is to press a button inside unity app on ios and run safari with a local pdf.
    I can run safari with online pdf from ios device and I can run the browser with local html from Android (not tested with pdf).
    I think this should be possible with OpenURL, because it's possible in MAC OS X.

    Joel
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    but thats because on osx the pdf file might have setup this relation ship

    on iOS there is no default app for PDF actually, that opens as the os itself does not have a viewer. The "official pdf viewer" would be iBooks, but thats not granted to be present (not even on new devices).

    What you optimally would do is implement a small overlay view that just loads the pdf as pdf support is present in cocoa touch.
     
  5. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    On iOS there is no default app for PDF, ok, but I want to use safari to open the pdf.
    I can open safari with my unity app and load an online pdf, for example:

    Application.OpenURL("http://download.unity3d.com/support/resources/files/3DPlatformTutorial.pdf")
    --> it works as I want because it lauches safari with the desired pdf

    But I want to load a local pdf, I want the same behaviour with local files, but that doesn't works:

    Application.OpenURL("file://" + Application.dataPath + "/Raw/myFile.pdf");

    Debug: file:///var/mobile/Applications/906956AE-AD40-402E-B4D9-BBD96F3ACAA2/SolerPalau.app/Data/Raw/myFile.pdf
    ...so the file exists, but safari isn't launched :_(

    Joel
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Thats access security.
    Applications can not access local data of other applications, only their own.

    But you can easily integrate a webview overlay into your app (there are a few plugins and free solutions for that) which does that cause its then your application and that one can access your files.
     
  7. gfoxworthy

    gfoxworthy

    Joined:
    Nov 4, 2010
    Posts:
    24
    @dreamora: I am trying to do the same thing with a PDF. Could you please direct us to the plugins and free solutions that would be easy to integrate? I am not familiar with iOS development outside of Unity.
     
    Last edited: May 13, 2011
  8. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    @gfoxworthy: I found a solution. You can use the Native Toolkit from Prime31 (free plugin).
    Use the function: public static void activateUIWithController( string controllerName )
     
  9. fenden

    fenden

    Joined:
    Dec 22, 2014
    Posts:
    8
    Is it an add-in can load PDF file in safari?
     
    siddharth3322 likes this.
  10. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    I am in the same condition, how to load view pdf file integrated in Unity project?