Open pdf

This method opens a pdf with Preview app (macOS)

it works ok with the two commented lines (asking the user to choose a file or opening a file in the Documents folder). But it fails when trying to open a PDF stored in the resources folder.
Is this an Apple limitation?

Sub Action() Handles Action
  var f as FolderItem = SpecialFolder.Resources.child("pggrules.pdf")
  // var f as FolderItem = SpecialFolder.Documents.Child("pggrules.pdf")
  // var f as FolderItem = FolderItem.ShowOpenFileDialog(FileTypes1.PDF)
  if f <> nil then
    Declare Function NSClassFromString Lib "Foundation" (name As CFStringRef) As Ptr
    Declare Function sharedApplication Lib "AppKit" Selector "sharedWorkspace" (obj As Ptr) As Ptr
    var sharedWorkspace As Ptr = sharedApplication(NSClassFromString("NSWorkspace"))
    Declare Function openFile Lib "AppKit" Selector "openFile:withApplication:" (id As Ptr, urlString As CFStringRef, appName As CFStringRef) As Boolean
    Call openFile(sharedWorkspace, f.NativePath, "")
  end if
End Sub

No. I force HTML help pages to open in the user’s web browser instead of the default app in case the user’s default app is BBEdit or the like.

Are you 100% positive the file is being copied and exists with the copy files step?

Thanks, I’ll try “force HTML help pages to open in the user’s web browser”

Well that’s just an example of what I do for opening a document from the resources of my application that I am sure works. I have to ask NSWorkspace what opens a web link and pass that application to openURL:bundleIdentifier:. If you are using a PDF, you should be able to just FolderItem.Launch it to open the user’s default app.

I use MBS to do this because I have that privilege. I unfortunately do not have declares for you.

I found the problem.
When a copy the pdf file to the project, Xojo changes the appendix from pggrules.pdf to pggrules.png.

That sounds like you may have dragged the file into the Navigator. You’ll need to use a CopyFiles step, which of course I can’t find any documentation for by searching “CopyFiles” on


Searching ‘copy files’ points to:

maybe that’s what you want?

Edit: maybe Xojo can update the search and give better results (or similar results) between ‘copyfiles’ and ‘copy files’?

1 Like

This is what I get:

XojoCloud and DoCommand are not documentation on how to use CopyFiles.

“Show all results…” provides just these two entries:

The entire time I’ve used Xojo it’s been a “CopyFiles” step to me. I guess that’s where the problem is.

1 Like

For better or worse, when you drag an item to the navigator, anything that the OS can identify as an image will be added to the project as a picture. macOS offers such capability, windows & Linux do not.

Generally, the two things that you might want to drag into the navigator are images or text files. Everything else belongs in a Copy Files Build Step as Tim has pointed out.

Are you saying that on MacOS, PDF dragged into the Navigator are rasterized to PNG files?

Yup. Anything that Picture.Open can handle.

The solution, as Tim, Greg, said is use CopyFiles.
Thanks all.

1 Like

You may want to mark this or Tim’s post as the answer - for someone in the future that maybe looking for a similar thing.