Open PDF file inside my application

Does anybody know how I can open a PDF file inside my application with HTMLviewer?

Same as with Desktop ?

Dim bundleFile As Xojo.IO.Folderitem
bundleFile = Xojo.IO.SpecialFolder.GetResource(“001.pdf”)
call ShowURL(bundleFile.URLPath)

From documentation:
URLPath As Text (read-only)

The URL path of the FolderItem, which uses the form file://path/to/file. It can be used to load a local file into an HTML viewer.

Sample Code

Get the URL path for a file:
Dim urlPath As Text = myFolderItem.URLPath

This will not work with “call ShowURL” or in a HTMLViewer with LoadURL(bundleFile.URLPath) in an iOS project. On macOS and Windows platform it works.

I will post the solution in a couple hours, currently driving around Norway. I did it in one of my apps

cool, I live in norway, vaccation?

Yes for two weeks, just arrived in Bergen, after visiting Oslo :slight_smile:

[quote=401970:@Horst Jehle]Dim bundleFile As Xojo.IO.Folderitem
bundleFile = Xojo.IO.SpecialFolder.GetResource(“001.pdf”)
call ShowURL(bundleFile.URLPath)[/quote]

This will not work because ShowURL opens the URL in Safari. Because of how iOS works, Safari doesn’t have access to files inside your app bundle.

Placing a HTMLViewer on an iOSView in your app, you can show the PDF file like this:

Dim pdfFile As xojo.IO.FolderItem
pdfFile = xojo.IO.SpecialFolder.Temporary.Child("file.pdf")

HTMLViewer1.LoadURL(pdfFile.URLPath)

file.pdf was previously created inside SpecialFolder.Temporary

It should also work if you get the file from the bundle: Xojo.IO.SpecialFolder.GetResource(“file.pdf”)

Direct access with “GetResource” and copy it to tmp folder doesn’t work im simulator or on real device. PDF file is in the right location when app runs in simulator.

pdfFile=file:///Users/pps4me/Library/Developer/CoreSimulator/Devices/D1399746-4A9F-4549-86A2-6BA0A5B6CBC4/data/Containers/Data/Application/E38EF88E-FA6A-4085-8F9F-866659A0DE0B/tmp/a.pdf

But it is not shown in the HTMLViewer.

With an html viewer called manualviewer on a view, all I do in the Open event is:

manualviewer.LoadURL SpecialFolder.documents.child("manual.pdf").URLPath
And this works for me.
The manual.pdf was dragged into the project before running, and I copy it into Documents at startup.

This code is essentially exactly what Jeromie is showing, but his uses the temporary folder

dim f as xojo.IO.FolderItem
f = xojo.IO.SpecialFolder.GetResource(“a.pdf”)
f.CopyTo(xojo.IO.SpecialFolder.Documents)

Dim pdfFile As xojo.IO.FolderItem
pdfFile = xojo.IO.SpecialFolder.Documents.Child(“a.pdf”)

if DebugBuild then
system.DebugLog “pdfFile=” + pdfFile.URLPath
// Shows: pdfFile=file:///Users/pps4me/Library/Developer/CoreSimulator/Devices/D1399746-4A9F-4549-86A2-6BA0A5B6CBC4/data/Containers/Data/Application/64D062AE-BDEC-41F1-A204-CB5EF783917F/Documents/a.pdf
end if

me.LoadURL(pdfFile.URLPath)

It doesn’t work with Xojo 2018R2 and Simulator Version 10.0 (SimulatorApp-851.2 CoreSimulator-518.22) and also on a real device.

Im using xojo 2018 1.1 and simulator 10 (835.5) and a real ipad

does pdfFile.exists = true at the point you want to use it?

After a week’s vacation, I have checked my project again and I have found the problem. The folder item for the pdf file are exists, but the HTMLView doesn’t show the pdf page. The HTMLView width was set to 0. That’s the reason why I can’t seen the pdf contents.

Thanks to all for help to find the error.

[quote=403300:@Horst Jehle]After a week’s vacation, I have checked my project again and I have found the problem. The folder item for the pdf file are exists, but the HTMLView doesn’t show the pdf page. The HTMLView width was set to 0. That’s the reason why I can’t seen the pdf contents.

Thanks to all for help to find the error.[/quote]

I was heading here to comment that the issue is similar to what’s being listed in https://forum.xojo.com/49721-blob-file-containing-pdf-to-webhtmlviewer but I see you’ve found your issue. Great!

Can some on confirm is this an issue with Xojo 2018r2? I have the same issue where I have to provide a path to the viewer on MAC Desktop. I did not have to do this a few weeks ago.