pdfjs
pdfjs copied to clipboard
Open local PDF file from FileSystem.AppDataDirectory
Hello good sir! I'm new to xamarin and I have to finish an important project, how can I pass a path to de view instead of a url. I already managed the download of images to the desired folder, but i'm having trouble working with pdf files. I'm saving the downloaded pdf inside a folder using the FileSystem API and it seems to work, now I just need to be able to view it inside the app itself. Also, is there a way I could pass the path to the downloads folder from the phone itself, since I managed to download pdf file to there as well. Thanks in advance for any and all help with this issue, Greeting from Chile!
Hi @leandro-chile,
Did you see the description for this in #1 ? I think that might help you :)
Hi @leandro-chile,
Did you see the description for this in #1 ? I think that might help you :)
Yes I did, but my problem is that I don't want to read a file from the assets directory, since I'm downloading it into the FileSystem.AppDataDirectory inside of a folder I created there. I tried passing the oath to the file directly into the browser with file:/// and content:// but none of that worked. looking at your code and some of the issues this is what I got:
localPath = FileSystem.AppDataDirectory + "/examenes/215/EXAMEN_MUTUAL000910.pdf"; if (Device.RuntimePlatform == Device.Android) PdfView.Source = $"file:///android_asset/pdfjs/web/viewer.html?file={"file:///" + WebUtility.UrlEncode(localPath)}"; else PdfView.Source = localPath; I don't get the "Failed to fetch" error anymore but I just get the black screen with the markers of a pdfviewer like the zoom in and out buttons, the page nav, etc. The alarming thing is that i even get that screen even with a path that leads to nowhere. Do you good sir, have any idea on how to solve this or help me in any way, I would greatly appreciate it. Greetings.
I saw the same issue. Fortunately I found the error from Application output. "Uncaught ReferenceError: require is not defined", source: file:///android_asset/pdfjs/web/viewer.js Unfortunately : I didn't find the solution.
Hi Gerald, I am trying to open local file, but its unable to find. I tried putting pdf into assets library as well as Environment.GetFolderPath(Environment.SpecialFolder.Personal) which is resolving to /data/user/0/com.companyname.amcdemo/files/sample.pdf
I also made sure file in asset library is androidasset. this is the error I am getting -
with asset folder -

with internal storage -
