- Home /
How to load pdf file with ios ?
Hi,
I need to open pdf files with ios for an industrial application. Currently I build pdf file from StreamingAssets folder which is then reading as bytes and writen in the documents folder of the app with FileStream library.
Pdf file looks ok on the Documents folder (I can see it in the Xcode app details panel) but i can't open it with the Application.OpenURL function, nothing happen whereas it works fine on my mac !
Here is the code :
private void WriteAndLoadFile()
{
string filePath = Path.Combine(Application.streamingAssetsPath, "file.pdf");
fileBytes = File.ReadAllBytes(filePath);
cachedFile = Path.Combine(Application.persistentDataPath, "file.pdf");
Debug.Log(cachedFile);
FileStream cache = new System.IO.FileStream(cachedFile, System.IO.FileMode.Create);
cache.Write(fileBytes, 0, fileBytes.Length);
cache.Close();
Application.OpenURL(cachedFile);
}
What i am doing wrong ??
Thanks !
$$anonymous$$aybe your url needs to start with file://
?
Hi, I'm struggling with the same issue on IOS. Could you find a solution?
Answer by AliasVincent · Apr 05, 2016 at 08:34 AM
Hello,
Check out this plugin : https://prime31.com/docs#iosEtc and look at the showWebPage function to open an external view of your pdf file.
Thanks, that's actually what I ended up doing. Unfortunately I couldn't find a way to open it without having to use external plugins and I guess you neither. But these prime31 plugins work like a charm. I could open not only PDF but also XLS, PPT, DOC, TXT, images, audio and video with the same method. Regards.
Answer by martejpad · Oct 30, 2017 at 11:29 AM
Hello!
I tried to do the same thing as @AliasVincent but came across the same problems. I ended up writing a native iOS plugin for Unity to preview a PDF file on iOS without leaving the app, I shared the code here:
I hope it helps!
Your answer
Follow this Question
Related Questions
Open a pdf file from the Resources folder on iOS 1 Answer
iOS Application.OpenUrl("app-settings:") Camera Crash Issue 1 Answer
Unity IOS - Open a In-App Web Browser 2 Answers
iOS Loading Local PDF/HTML from StreamingAssets 0 Answers
Alternative to 'Application.OpenURL()' for newest Android API 1 Answer