Help displaying a pdf in an HTMLViewerControl

I am not having much luck with this. I want to display a pdf that resides on the server in an HTMLViewer control. To make it as simple as possible I put a pdf on my Desktop (Mac OS X). It seems like this should work…

  dim myPDFFile as New WebFile
  Dim f As FolderItem = SpecialFolder.Desktop.Child("Testing.pdf")
  myPDFFile = new WebFile  
  myPDFFile.MIMEType = "application/pdf"
  myPDFFile =
  HTMLViewer1.URL = myPDFFile.URL

I get a 404 file not found error in the HTMLViewer…

[quote]404: File Not Found
The requested URL “/E22CB1B4518168ACA14E70DBCC29CF3A/files/5819-4096-6409-9641-9245/Testing.pdf” could not be found. Please check your request and try again.[/quote]

I am struggling to understand how to access the web server’s file system in Xojo so any help would be appreciated.

Not at my Desk right now, i would recommend to access the file using it’s native path.

In the open event use this:

First, you need to make myPDFFile a property of your WebPage so it does not get out of scope.

The funny thing is, even with that modification, a jpeg displays perfectly, but the browser insists on downloading the PDF.

Yet, if I drag the PDF over the browser window, it displays very nicely.

The URL is good : if I actually download the file it is valid and displays fine when double clicked. I also made sure ForceDownload is false.

@Michel Bujardet That Worked!

Wow. So simple. So now my code now looks like this…

  Dim f As FolderItem = SpecialFolder.Desktop.Child("Testing.pdf")
  myPDFFile = WebFile.Open(f)
  myPDFFile.MIMEType = "application/pdf"
  HTMLViewer1.URL = myPDFFile.URL

Works Great. Thanks Michel


The LR is your friend at :